Help with sscanf2
#1

Hey dear,

i have still a little question by using sscanf2:

How can I do it like this?

pawn Код:
if(strcmp(string,"/shop",true) == 0)
{
    new x_nr[64];
    x_nr = strtok(cmdtext, idx);
    if(!strlen(x_nr)) return SendClientMessage(playerid, 0xAA3333AA,"ERROR: /shop [buy/sell/own]");
    if(strcmp(x_nr,"buy",true) == 0)
    {
        //some stuff here
    }
    else if(strcmp(x_nr,"sell",true) == 0)
    {
        //some stuff here
    }
    else if(strcmp(x_nr,"own",true) == 0)
    {
        //some stuff here
    }
    return 1;
}
I try it like this:

pawn Код:
COMMAND:shop(playerid, params[])
{
    new act[7];
    if (!sscanf(params, "s", act))
    {
        if(!sscanf("buy","s",act))
        {
            //some stuff here
        }
        else if(!sscanf("sell","s",act))
        {
            //some stuff here
        }
        else if(!sscanf("own","s",act))
        {
            //some stuff here
        }
    } else SendClientMessage(playerid, 0xAA3333AA,"ERROR: /shop [buy/sell/own]");
    return 1;
}
But it didnt work, if I type in /shop sell (same with /show own), it shows me the code from /shop buy.

How can I do such a thing with sscanf? Sorry, im really new to sscanf, I allways used strcmp.

Thanks for help.
Reply
#2

You don't need sscanf for one parameter. isnull() comes with zcmd.
PHP код:
CMD:command(playeridparams[])
{
    if(
isnull(params)) {
        return 
SendClientMessage(playerid, -1"USAGE: /command [name]");
    }
    
    else if(!
strcmp(params"car"true)) {
        
// player typed car after /command
    
}
    
    else if(!
strcmp(params"apple"true)) {
        
// player typed apple after /command
    
}
    return 
1;

Reply
#3

Thanks a lot.

test
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)