Making SSCANF optional - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Making SSCANF optional (
/showthread.php?tid=275551)
Making SSCANF optional -
emokidx - 10.08.2011
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..
Re: Making SSCANF optional -
Grim_ - 10.08.2011
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'.
Re: Making SSCANF optional -
emokidx - 10.08.2011
oh,, thnx
Re: Making SSCANF optional -
Godhimself - 10.08.2011
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.