sscanf questions - 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)
+--- Thread: sscanf questions (
/showthread.php?tid=608479)
sscanf questions -
sam29 - 01.06.2016
Hello,
I would like to do a command where when params is empty, it does an action but when i give an id, it does the action on the player. I'm currently using :
if(isnull(params))
{
}
else
{
}
Is there any way to do this with sscanf
2)
Also, i would like to do a cmd where either i give an id or a part of name of players in params. i'm currently using
if(!IsNumeric(params)) player1 = ReturnPlayerID(params);
is there any ways with sscanf
Thank for your answers
Re: sscanf questions -
Konstantinos - 01.06.2016
1)
pawn Код:
new
id;
if (sscanf(params, "r", id)) id = playerid;
"id" will either hold the player's ID given or the player's who executed the command if none/wrong parameter(s) passed.
2) sscanf does that already! Using "r" (players only) or "u" (players + NPCs) specifiers will accept ID/part of name. So all those IsNumeric and ReturnPlayerID are not needed at all.
Re: sscanf questions -
sam29 - 01.06.2016
Thank you for your answer, I imagin it is sscanf2 who can do this and not the old pawn version ?
Re: sscanf questions -
Konstantinos - 01.06.2016
The old Pawn version still had "u" specifier but it is deprecated. You better use the plugin version (sscanf2.inc).
Re: sscanf questions -
F1N4L - 01.06.2016
The params, in this case, is a string. Then you have to convert String in Integer with strval.
Examples:
Search ID with isnull
Код:
if(isnull(params))
{
// code to return false
}
else // code to return true
{
if(IsPlayerConected(strval(params)))
{
// Player Conected
}
}
Search ID with sscanf
Код:
new Target;
if(sscanf(params, "i", Target))
{
// code to return false
}
else // code to return true
{
if(IsPlayerConected(Target))
{
// Player Conected
}
}