SA-MP Forums Archive
/makeadmin - 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: /makeadmin (/showthread.php?tid=506280)



/makeadmin - D3vin - 12.04.2014

I wanted to put something like to prevent people from demoting high level admins for example i'am a Community Director but Executive Admins can use /makeadmin on me and demote me to Level 1 so i want a script to prevent this but i really didn't know how

pawn Код:
if(strcmp(cmd, "/makeadmin", true) == 0)
    {
        if(PlayerInfo[playerid][pAdmin] >= 99999)
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /makeadmin [playerid/PartOfName] [level]");
                return 1;
            }
            new para1;
            new level;
            para1 = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /makeadmin [playerid/PartOfName] [level]");
                return 1;
            }
            level = strvalEx(tmp);
                        if(level > 99999 || level < 0) { SendClientMessage(playerid, COLOR_GREY, "   Don't go below number 0, or above number 99999 (1/2/3/4/1337/99999) !"); return 1; }
            if(IsPlayerConnected(para1))
            {
                if(para1 != INVALID_PLAYER_ID)
                {
                    strmid(giveplayer, PlayerRPName(para1), 0, MAX_PLAYER_NAME);
                    strmid(sendername, PlayerRPName(playerid), 0, MAX_PLAYER_NAME);
                    if(level < 2) PlayerInfo[para1][pTag] = NTAG_PLAYER;
                    else PlayerInfo[para1][pTag] = NTAG_ADMIN;

                    if(level > 0)
                    {
                        new rand = random(9999);
                        PlayerInfo[para1][pSecKey] = rand;
                        gAdminAuthorized[para1] = 1;
                    }

                    if(level > PlayerInfo[para1][pAdmin])
                    {
                        format(string, sizeof(string), "   You have been promoted to a level %d admin by %s, your security key is %d.", level, sendername, PlayerInfo[para1][pSecKey]);
                        SendClientMessage(para1, COLOR_LIGHTBLUE, string);
                        format(string, sizeof(string), "   You have promoted %s to a level %d admin.", giveplayer,level);
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                    }
                    else
                    {
                        format(string, sizeof(string), "   You have been demoted to a level %d admin by %s, your security key is %d.", level, sendername, PlayerInfo[para1][pSecKey]);
                        SendClientMessage(para1, COLOR_LIGHTBLUE, string);
                        format(string, sizeof(string), "   You have demoted %s to a level %d admin.", giveplayer,level);
                                        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                    }
                   
                    PlayerInfo[para1][pAdmin] = level;
                   
                    if(level < 1)
                    {
                        PlayerInfo[para1][pAdmin] = 0;
                        PlayerInfo[para1][pSecKey] = 0;
                        gAdminAuthorized[para1] = 0;
                    }
                }
            }
        }
    }



Re: /makeadmin - PrivatioBoni - 12.04.2014

That code is impossible to read, partially due to the weird style (e.g. you should consider using sscanf, ZCMD) and the fact it's in [code] and not [pawn], however, you could add this line somewhere (not sure if I've used the correct variable name):

pawn Код:
if(PlayerInfo[para1][pAdmin] > PlayerInfo[playerid][pAdmin])
{
   SendClientMessage(playerid, COLOR_RED,  "Cannot edit this user's admin level.");
   return 1;
}



Re: /makeadmin - D3vin - 12.04.2014

It worked but it changes my security Key and i get message i got demoted to level 0 admin ........ect...and my security key......blabla

so they really can change my security key after demoting me but when ui talk on Admin chat it says Community Director so i'am not demoted