Invalid player ID with sscanf
#1

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

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

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

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

Put the plugin first and all of your problem is gone
Reply
#6

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?..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)