sscanf | multiple sub-cmds for a sub-cmd.
#1

Well, I actually never managed to get a command like /car get (has 1 paramter, id)/create(has multiple paramters like model, colors etc) to get it working with sscanf only, I always got some warnings of format specificer does not match parameter count, etc..
If someone has any example code for me or could tell me how to do it exactly that'd be great.
Thanks!
Reply
#2

You can do this for the /car get command.

pawn Код:
CMD:carget(playerid, params[])
{
new vehicleid;
if (sscanf(params, "d", vehicleid)) SendClientMessage(playerid, -1, "USAGE: /carget [vehicleid]");
new
Float: x,
Float: y,
Float: z;
GetPlayerPos(playerid, x, y, z);
SetVehiclePos(vehicleid, x, y, z);
}
This would allow you to teleport a given vehicle to your position, - using ZCMD.
Reply
#3

Quote:
Originally Posted by Itzhak E.
Посмотреть сообщение
Well, I actually never managed to get a command like /car get (has 1 paramter, id)/create(has multiple paramters like model, colors etc) to get it working with sscanf only, I always got some warnings of format specificer does not match parameter count, etc..
If someone has any example code for me or could tell me how to do it exactly that'd be great.
Thanks!
You can either use the optional sscanf parameters after the mandatory string, for example:

pawn Код:
new option[12],param[5];
sscanf(params,"s[12]I(0)I(0)I(0)I(0)", option, param[0],param[1],param[2],param[3],param[4]);
Then use the parameters you need, for example, if you had a /car create model color1 color2

pawn Код:
if(strcmp(option,"create",false) == 0)
{
    new model = param[0];
    new color = param[1];
    new color2 = param[2];
}
Other thing would be to sscanf the parameters STARTING from the second text parameter, example:

pawn Код:
new option[12];
sscanf(params,"s[12] ",option);

if(strcmp(option,"create", false) == 0)
{
    new model, color, color2;
    sscanf(params[strlen(option)],"iii", model, color, color2);
}
If you do params[0] or params it, it will return the whole string, if you do params[1] it will return the whole string starting from the second character, and so on.


EDIT:

This

pawn Код:
new params[128];
new option[12];
strcat(params, "create 400 2 2");
sscanf(params, "s[12] ", option);
printf("%s",option);
new model, color, color2;
sscanf(params[strlen(option)],"iii",model, color, color2);
printf("%d %d %d", model, color, color2);
Effectively returns

Код:
create
400 2 2
It is very important the space on the first sscanf: "s[12] ", notice how there is a space after the ] and before the closing "
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)