SA-MP Forums Archive
Big "strtok" error/bug. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Big "strtok" error/bug. (/showthread.php?tid=206835)



Big "strtok" error/bug. - linuxthefish - 04.01.2011

When i type the command /pfo it says "Corerct usage /pfo [playerid] [ammount" which is ok. But when i type /pfo 0 50 it says unknown command. Can someone tell me what to do to fix it??

http://linuxthefish.pastebin.com/Npx6WgWB


Re: Big "strtok" error/bug. - Kwarde - 04.01.2011

Because you have 2 params, you need strtok twice
And you can better use zcmd/dcmd and use sscanf. It's hell faster


Re: Big "strtok" error/bug. - _rAped - 04.01.2011

Are you aware of the amazing tool sscanf?


Re: Big "strtok" error/bug. - linuxthefish - 04.01.2011

How can i change strtok into sscanf? I cant find a good tutorial on it.


Re: Big "strtok" error/bug. - Kwarde - 04.01.2011

Quote:
Originally Posted by linuxthefish
Посмотреть сообщение
How can i change strtok into sscanf? I cant find a good tutorial on it.
Ehm here's a small, little command, used with dcmd. It's an /me command.

pawn Код:
dcmd_me(playerid, params[])
{
    new Action[100]; //Used for the param. Important!
    new str[128], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s", action)) return 0; //No param used.
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    format(str, 128, "%s %s", pName, Action);
    SendClientMessageToAll(0xFFFFFFAA, str);
    return 1;
}
When you use 'if(sscanf' stuff, it will show you when there is NO param filled in. The 's' is the string. It's the same with formatting: '%s'. So 'd', 'i' or 'u' etc are integers. 'f' is a float. Get it? And after that, use the strings you want to use.
if(sscanf(params, "ds", giveplayerid, reason)).
This is mostly used for ban/kick commands. the 'd' is an integer and the 's' is the string. Behind that, use the strings you wanna use in the script.
Sorry if I am unclear. I hope that you understand this


Re: Big "strtok" error/bug. - _rAped - 04.01.2011

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Ehm here's a small, little command, used with dcmd. It's an /me command.

pawn Код:
dcmd_me(playerid, params[])
{
    new Action[100]; //Used for the param. Important!
    new str[128], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s", action)) return 0; //No param used.
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    format(str, 128, "%s %s", pName, Action);
    SendClientMessageToAll(0xFFFFFFAA, str);
    return 1;
}
When you use 'if(sscanf' stuff, it will show you when there is NO param filled in. The 's' is the string. It's the same with formatting: '%s'. So 'd', 'i' or 'u' etc are integers. 'f' is a float. Get it? And after that, use the strings you want to use.
if(sscanf(params, "ds", giveplayerid, reason)).
This is mostly used for ban/kick commands. the 'd' is an integer and the 's' is the string. Behind that, use the strings you wanna use in the script.
Sorry if I am unclear. I hope that you understand this
Another example of how to use sscanf with zcmd:
pawn Код:
COMMAND:me(playerid, params[])
{
    new text[128], string[128];
    if(sscanf(params, "s[64]", text)) return SendClientMessage(playerid, COLOR_WHITE, "ERROR » That's not the way, try: /me (action)");
    format(string, sizeof(string), "{C688D4}** %s %s", RemoveUnderScore(playerid), text);
    NewProx(playerid, COLOR_WHITE, string, 30.0);
    return 1;
}



Re: Big "strtok" error/bug. - Kwarde - 04.01.2011

Omg I guess you copied it from a script. "NewProx" and "RemoveUnderScore" aren't standard functions.
However, here's another example indeed :P


Re: Big "strtok" error/bug. - linuxthefish - 04.01.2011

I copied the original bit from a admin script, and them replaced what i think is the right bit with "GetPlayer Velocity" and "SetPlayerVelocity". I'm just not to sure on sscanf/strok but i've used zcmd in the past. Thanks for your help though


Re: Big "strtok" error/bug. - Sergei - 04.01.2011

Why using sscanf for single parameter (especially string)? Just use isnull.


Re: Big "strtok" error/bug. - Kwarde - 04.01.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
Why using sscanf for single parameter (especially string)? Just use isnull.
1: isnull is not an samp standard function.
2: It was an example script :')