Making SSCANF optional
#1

hello
i want to know how to make a command that can be used without the ID and with the ID as well.. E.G.

if i do /stats i get my own /stats and if i do /stats [id] (/stats 3) i get the stats of the playerid 3..
Reply
#2

pawn Код:
COMMAND:stats( playerid, params[ ] )
{
   if( isnull( params ) )
   {
      // Show player their own stats
   }
   else
   {
      new id = strval( params );
      if( !IsPlayerConnected( id ) ) return 0;
      // Show 'id' player stats
   }
   return 1;
}
There is no need to use sscanf as you are only looking for one parameter. However, if you get more, to make a parameter optional in sscanf, make the letter capitalized. For example, if you were looking for an optional integer, instead of using 'i', you'd use 'I'.
Reply
#3

oh,, thnx
Reply
#4

Grim_'s code will work, But i noticed u asked for sscanf, here is a sscanf rebuild:

pawn Код:
COMMAND:stats(playerid, params[])
{
   new otherplayerid;
   if(isnull(params))
   {
       // Show player their own stats
   }
   else if(!sscanf(params, "u", otherplayerid))
   {
       // Show the 'otherplayerid' stats
   }
   else
   {
       SendClientMessage(playerid, -1, "USAGE: /stats [name/id]");
   }
   return 1;
}
Not tested. Should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)