Hello!
I have ported this code from the AMXX:
PHP Code:
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo = {
name = "Test Parse",
author = "Ludak",
description = "Test Parse",
version = "1.0.0",
url = ""
};
public void OnPluginStart() {
AddCommandListener(Chat_Handle, "say");
}
public Action Chat_Handle(int player, const char[] command, int argCommands) {
if (IsClientInGame(player)) {
char message[256];
GetCmdArgString(message, sizeof(message));
StripQuotes(message);
if (!strlen(message))
return Plugin_Handled;
if (StrEqual(message, "/parse")) {
PrintToChat(player, "---------> Test <--------- ");
char results[12][256];
int number = ParseTest("(some,(weird,string),list,1234,,(more,text,in,a,substring),some,more,$$$,###,@annotation)", results, 256);
for (int i = 0; i < number; i++)
PrintToChat(player, "Part %d: %s", i + 1, results[i]);
PrintToChat(player, "---------> Test <--------- ");
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public int ParseTest(const char[] text, char[][] results, int maxLength) {
int index = 0;
int items = 0;
int startIndex = 0;
int len = 0;
int parenthesesCounter = 0;
while (text[index] != EOS) {
if (text[index] == '(')
parenthesesCounter++;
if (text[index] == ')')
parenthesesCounter--;
if ((text[index] == ',' || text[index + 1] == EOS) && parenthesesCounter == 0) {
len = index - startIndex + (text[index + 1] == EOS ? 1 : 0);
strcopy(results[items++], maxLength < len ? maxLength : len, text[startIndex]);
items++;
startIndex = index + 1;
}
index++;
}
return items;
}
But the problem that it is not working, it just prints this output:
Instead of:
PHP Code:
Part 1: some
Part 2: (weird,string)
Part 3: list
Part 4: 1234
Part 5:
Part 6: (more,text,in,a,substring)
Part 7: some
Part 8: more
Part 9: $$$
Part 10: ###
Part 11: @annotation
The original AMXX Code:
https://forums.alliedmods.net/showpo...99&postcount=4
I do not know that is wrong with it, everything seems normal.
I have tried using '\0' instead of EOS, it does not work.
Can someone help me, thank you.
Also, it is possible to pass ArrayList by a reference and push the resulting string into it?
I am new to source pawn and programming in general.