multiple parameters using sscanf
#1

i'm just wondering, how to do this? I mean a command like: /trunk [store, get, show] [item] [name, amount]
Reply
#2

pawn Code:
new
     action[6], // store is 5 characters long (and the longest word), add another to make it big enough.
     item[64], //Assuming that the item parameter is going to be a string/name.
     amount //Assuming a number/integer.
;
//Template: sscanf(input_string, format/specifiers, output_variables in order of appearence in specifiers);
sscanf(params, "s[6]s[64]i", action, item, amount);
Hopefully this explains it well enough.
Reply
#3

Use what funky posted. You'd then check inside the command on what action they specified (to store, get or show) with a simple if/else if expression:

pawn Code:
if( !strcmp(action, "store") )
{
    // .. They want to store
}
else if( !strcmp(action, "get") )
{
    // .. They want to get
}
else if( !strcmp( action, "show") )
{
    // .. They want to show
}
else
{
    // .. Unknown action
}
Reply
#4

yeah, I did that but what about this: /trunk store weapon desert? the amount should be integer OR string, that's what I can't do

blewert: I did that before to make this topic..

nvm.. strval did it
Reply
#5

Here, Next time use ****** to search.
pawn Code:
CMD:take(playerid, params[])
{
    if(!strlen(params))
    {
        SendClientMessage(playerid, -1,"Syntax: /take [option]");
        SendClientMessage(playerid, -1,"Drugs - Crack - Pot - Money");
    }
    else if(strcmp(params,"drugs",true) == 0)
    {
   
   
   
    }
    else if(strcmp(params,"crack",true) == 0)
    {



    }
    else if(strcmp(params,"pot",true) == 0)
    {



    }
    else if(strcmp(params,"money",true) == 0)
    {



    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)