StrtoK
#1

Hey all :P ,
I am a beginner programmer pawn
I want to know what it is and what it does strtok
Thanks to helpers!
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);
 
    if(strcmp(cmd, "/kick", true) == 0)
    {
        new tmp[128];
        tmp = strtok(cmdtext, idx);
 
        if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /kick [playerid]");
 
        Kick(strval(tmp));
        return 1;
    }
    return 0;
}
You can see in this command that strtok changes the way we write our command (in this example /kick).
The key line is
Код:
cmd = strtok(cmdtext, idx);
and
Код:
tmp = strtok(cmdtext, idx);
because after using this you can see that the way these commands are set, is different than usual.
Strtok is a very important function in your script if you don't want the server to return you "UNKNOWN COMMAND" when you write something that doesn't exist.
Reply
#3

I truly don't know why all beginners start by learning the most outdated methods. Download some recent scripts from the gamemodes section and explore those. Most of the default gamemodes haven't been updated since SA-MP was first released.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)