question on sscanf
#1

i'm just new to zcmd and sscanf and i was wondering on how to do something similar to strtok.

example:

the command is /setstat and there are several options, like money, level, skin, etc.

pawn Код:
command(setstat, playerid, params[])
{
    new id, option[15];
    sscanf(params, "us[15]", id, option);
    if(isnull(id)) return SendClientMessage(playerid, -1, "usage: /setstat [playerid] [option]");
    if(isnull(id) && isnull(option)) return SendClientMessage(playerid, -1, "usage: /setstat [playerid] [option]");
    if(!strcmp(option, "level", true))
    {
        // what should i do here?
    }
    return 1;
}
on the comment, it says "what should i do here?" and i mean what code should i put in to check the next parameter after the option which is level?
Reply
#2

You can make something like this if you like to:

pawn Код:
CMD:setstat(playerid, params[])
{
    new id, option, set;
    if(sscanf(params, "udd", id, option, set)) return SendClientMessage(playerid, -1, "usage: /setstat [playerid] [option] [set]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "That player doesn't exist.");
    else
    {
         if(option <= 0 || option > 4) return SendClientMessage(playerid, -1, "1 - money , 2 - skin , 3 - score, 4 - level");
         if(option == 1) // this will set the money
         {
              GivePlayerMoney(id, set);
         }
         else if(option == 2) // skin
         {
           // code here
         }
         // ... and so on, you got the idea I guess
    }
    return 1;
}
EDIT: lol I forgot some minor things
Reply
#3

what you've shown me is the same with what i have posted. you're using integers for the options while i used strings. what i'm looking for is the code that would be placed in them for checking the next parameter if and only if that option was used.

anyway, thanks for trying.
Reply
#4

Something like this perhaps?

pawn Код:
command(setstat, playerid, params[])
{
    new id, option[15], second[30];
    if(sscanf(params, "us[15]S(null)[30]", id, option, second)) return SendClientMessage(playerid, -1, "usage: /setstat [playerid] [option]");
    if(!strcmp(option, "level", true))
    {
        if(!strcmp(second, "null", true)) return SendClientMessage(playerid, -1, "usage: /setstat [playerid] [level] [value]");
        new Level = strval(second);
        //the rest of your code (this is just an example with it being an integer)
    }
    else if(!strcmp(option, "Name", true))
    {
        if(!strcmp(second, "null", true)) return SendClientMessage(playerid, -1, "usage: /setstat [playerid] [name] [newname]");
        SetPlayerName(playerid, second);
        //and the other stuff (this is just an example with it being a string)
    }
    return 1;
}
Reply
#5

thanks antonio, got a reputation point from me and hello if i'm not mistaken that you're the antonio i met on the abk clan. if you know freshkid and mo bustin then it's you. unless you're an impostor.
Reply
#6

Lol, ofc I know them :P (where fresh been? last i heard he was tryin to get a new PC)
Reply
#7

haven't heard from him since the good old sarp days. so it's you, nice to see abk back. you were the one who taught me how to crack-shoot, lol.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)