sscanf multiple paramteres usage -
Ripster - 01.08.2016
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!
Re: sscanf multiple paramteres usage -
J0sh... - 01.08.2016
PHP код:
if(sscanf(params, "s[25]I(0)" , whatever, ...))
(0) is the default value.
Re: sscanf multiple paramteres usage -
Luicy. - 01.08.2016
PHP код:
new action[5], quantity;
if(!sscanf(params, "s[5]i", action, quantity)) {
if(!strcmp(action, "take")) {
// /trunk take /quantitity/
}
else if(!strcmp(action, "put")) {
// /trunk put /quantitity/
}
else
SendClientMessage(playerid, 0xCC0000FF, "Usage: /trunk [take/put] [quantity]");
}
else if(!sscanf(params, "s[5]", action)) {
if(!strcmp(action, "take")) {
SendClientMessage(playerid, 0xCC0000FF, "Usage: /trunk take [quantity]");
}
else if(!strcmp(action, "put")) {
SendClientMessage(playerid, 0xCC0000FF, "Usage: /trunk put [quantity]");
}
else if(!strcmp(action, "show")) {
// /trunk show
}
else
SendClientMessage(playerid, 0xCC0000FF, "Usage: /trunk[ put/take/show]");
}
Enjoy.
Re: sscanf multiple paramteres usage -
Ripster - 01.08.2016
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.
Re: sscanf multiple paramteres usage -
Konstantinos - 01.08.2016
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;
Re: sscanf multiple paramteres usage -
Stinged - 01.08.2016
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.