SA-MP Forums Archive
Invalid player ID with sscanf - 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: Invalid player ID with sscanf (/showthread.php?tid=328844)



Invalid player ID with sscanf - DBan - 26.03.2012

Hi all!

I am trying to make a /setadmin command but whenever I try to do the command on myself, it gives returns with Invalid Player ID automatically. Is this normal? Did I make a mistake in my code?

pawn Код:
CMD:setadmin(playerid,params[])
{
    if (PlayerInfo[playerid][AdminLevel] <= 5)
    {
        MESSAGE(cred, errorna);
    }
    if (PlayerInfo[playerid][AdminLevel] >= 6)
    {
        new id, pname[MAX_PLAYER_NAME], lvl;
        GetPlayerName(id, pname, sizeof(pname));
        if(sscanf(params, "ud", id, fString, lvl)) return MESSAGE(cred, "USAGE:{FFFFFF} /setadmin [name/id] [level]");
        else if(id == INVALID_PLAYER_ID) return MESSAGE(cred, invalid);
        else
        {
            PlayerInfo[id][AdminLevel] = 6;
            format(fString2, sizeof(fString2), "Admin level set for %s", id);
            MESSAGE(cyellow, fString2);
            format(fString3, sizeof(fString3), "Admin level (%d) set by admin", lvl);
            SendClientMessage(id, cwhite, fString3);
        }
    }
    return 1;
}
I'm pretty sure it's a newbie mistake.

Thanks!

BTW:
pawn Код:
MESSAGE(color, const[]); //I defined this at the top, this is SendClientMessage(playerid



Re: Invalid player ID with sscanf - Reklez - 26.03.2012

pawn Код:
if(id == INVALID_PLAYER_ID)
remove the else


Re: Invalid player ID with sscanf - DBan - 26.03.2012

Quote:
Originally Posted by Reklez
Посмотреть сообщение
pawn Код:
if(id == INVALID_PLAYER_ID)
remove the else
It still does the same thing, but thanks for replying


Re: Invalid player ID with sscanf - Ronaldo_raul™ - 26.03.2012

pawn Код:
CMD:setadmin ( playerid , params [] )
{
    if ( PlayerInfo [ playerid ][ AdminLevel ] <= 5) return MESSAGE(cred, errorna);
    new ID , LvL , pName [ MAX_PLAYER_NAME ] ;
    GetPlayerName ( ID , pName , MAX_PLAYER_NAME ) ;
    if ( !IsPlayerConnected ( ID ) ) return MESSAGE(cred, invalid);
    if ( sscanf ( params "ud" , ID , LvL ) ) return MESSAGE ( cred , "USAGE:{FFFFFF} /setadmin [name/id] [level]" ) ;
    else
    {
    PlayerInfo[id][AdminLevel] = 6;
    new Str [ 128 ] ;
    format ( Str , 128 , "Admin level set for %s" , ID ) ;
    MESSAGE ( cyellow , Str ) ;
    format ( Str , 128 , "Admin level (%d) set by admin" , LvL ) ;
    SendClientMessage ( ID , cwhite , Str);
   
    }
    return 1;
}
Not Tested.


Re: Invalid player ID with sscanf - cristip - 25.05.2013

Put the plugin first and all of your problem is gone


Re: Invalid player ID with sscanf - Littlehelper - 25.05.2013

Quote:
Originally Posted by cristip
Посмотреть сообщение
Put the plugin first and all of your problem is gone
You have bumped 1 year old topic just to say this?..