18.03.2010, 23:39
It's used to find a variable after a space. Like a command /ban <playerid>. It will not work if you do /ban5 ( Trying to ban id 5 ). So strtok finds the variable after a space so you can do /ban 5 ( Bans id 5 ). The parameters are explained like this ( in my way ):
const string[], &index
The const string[] is to search a string and find a variable after the space, so like in OnPlayerCommandText, strtok looks for a space ( Like the example above /ban (THE SPACE) 5 ) after the command you put in.
The &index is not something I don't understand 100%, but all I know is that it's used to store a random variable and it's needed for the function to run.
I'll show you a strtok examples.
strlen checks the length of a string. So if strlen is 0 that means it will return. So read closely, I will explain how this worked out.
if(!strlen(ptext))
if = if
!strlen(ptext) = The string text is 0.
So if the string text is 0 then return that message.
Translated
If there's no space between @ and the message, then return that message
Do you understand now?
const string[], &index
The const string[] is to search a string and find a variable after the space, so like in OnPlayerCommandText, strtok looks for a space ( Like the example above /ban (THE SPACE) 5 ) after the command you put in.
The &index is not something I don't understand 100%, but all I know is that it's used to store a random variable and it's needed for the function to run.
I'll show you a strtok examples.
pawn Код:
public OnPlayerText(playerid, text[]) {
new ptext[128], rvar;
ptext = strtok(text, rvar);
if(strcmp(ptext, "@", true) == 0)
{
if(!strlen(ptext)) return SendClientMessage(playerid, MY_COLOR, "@ <Admin chat message>");
}
}
if(!strlen(ptext))
if = if
!strlen(ptext) = The string text is 0.
So if the string text is 0 then return that message.
Translated
If there's no space between @ and the message, then return that message
Do you understand now?