sscanf multiple paramteres usage
#1

Hey guys!
I’m using sscanf, and I’d like to create a command, in which I’d use multiple parameters. My example would be the following:
/trunk [show/take/put] [quantity]
Now if I take something out, or put something in, it’s obvious that I have to use quantity. But in ’show’s case, I don’t need quantity. So the question is… How do I make this work, without having to use a quantity number when I use /trunk show
Thank you for your help!
Reply
#2

PHP код:
if(sscanf(params"s[25]I(0)" whatever, ...)) 
(0) is the default value.
Reply
#3

PHP код:
new action[5], quantity;
if(!
sscanf(params"s[5]i"actionquantity)) {
   if(!
strcmp(action"take")) {
      
// /trunk take /quantitity/
   
}
   else if(!
strcmp(action"put")) {
      
// /trunk put /quantitity/
   
}
   else
      
SendClientMessage(playerid0xCC0000FF"Usage: /trunk [take/put] [quantity]");
}
else if(!
sscanf(params"s[5]"action)) {
   if(!
strcmp(action"take")) {
      
SendClientMessage(playerid0xCC0000FF"Usage: /trunk take [quantity]");
   }
   else if(!
strcmp(action"put")) {
      
SendClientMessage(playerid0xCC0000FF"Usage: /trunk put [quantity]");
   }
   else if(!
strcmp(action"show")) {
      
// /trunk show
   
}
   else
      
SendClientMessage(playerid0xCC0000FF"Usage: /trunk[ put/take/show]");

Enjoy.
Reply
#4

And what happens in this case?
Код:
if(sscanf(params, "s[16]s[16]d(0)d(0)", command, command2, slot)) return 1;

    /v trunk show
    /v trunk put 1 1
    /v lights
As in the last command there isn’t a third element, I don’t know if it’d still work.
Reply
#5

So it may or may not have an extra string and 2 integers?

That would make it:
pawn Код:
new command[16], command2[16], slot, slot2;
if (sscanf(params, "s[16]S()[16]D(0)D(0)", command, command2, slot, slot2)) return 1;
Reply
#6

I'm just giving an extra method of doing that.
Код:
new value1, value2;
if (!strcmp(params, "option1", true, 7))
{
    if (sscanf(params[8], "ii", value1, value2))
        return Usage message "/cmd option1 [value1] [value2]";
}
else if (!strcmp(params, "option2 ExtraOption", true, 19))
{
    if (sscanf(params[20], "i", value1))
        return Usage message "/cmd option2 ExtraOption [value1]";
}

/cmd [option] [whatever]
I think it's better, because strings with spaces can cause problems with detecting them in sscanf.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)