Big "strtok" error/bug.
#1

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
Reply
#2

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

Are you aware of the amazing tool sscanf?
Reply
#4

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

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
Reply
#6

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;
}
Reply
#7

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

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
Reply
#9

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

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 :')
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)