sscanf Help
#1

I feel like a proper idiot for asking this but i COMPLETELY forgot how to use sscanf and the tutorial is like Mandarin to me.

Im making a ZCMD command which is as follows: /ban [username/id] [days] [reason]

Can someone show me how that is processed with ZCMD and SSCANF?
Reply
#2

pawn Код:
COMMAND:mycommand(playerid, params[])
{
   new target,days,reason[80];
   if (sscanf(params, "uis[80]", target,days,reason)) return //param missing

  return 1;
}
U do the rest

Or
pawn Код:
COMMAND:mycommand(playerid, params[])
{
   if (sscanf(params, "uis[80]", params[0],params[1],params[2])) return //param missing
}
Reply
#3

If you want definite results use sscanf like this.
pawn Код:
CMD:ban(playerid, params[])
{
    new pid, days, reason[128];
    if(sscanf(params, "uis[128]", pid, days, reason)) return SendClientMessage(playerid, 0xFF00FFFF, "Usage /ban <ID> <Days> <Reason>");
    ........
}
Ok well suppose you wanted your ban to work without days or a reason you can just do it like this then make some checks after to determine which gives a more specific result for instance.

pawn Код:
CMD:ban(playerid, params[])
{
    new pid, days, reason[128];
    sscanf(params, "uis[128]", pid, days, reason)
    if(days < 0) days = 1; // Default days
    ........
}
I prefer this method hands down.
Reply
#4

Thanks guys! Its starting to come back to me now! I appreciate it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)