sscanf questions
#1

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
Reply
#2

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.
Reply
#3

Thank you for your answer, I imagin it is sscanf2 who can do this and not the old pawn version ?
Reply
#4

The old Pawn version still had "u" specifier but it is deprecated. You better use the plugin version (sscanf2.inc).
Reply
#5

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
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)