07.07.2012, 16:16
I optimised your code.
I'm assuming player's stats get saved on quit, so I just set their admin VARIABLE to "lvl" and also added a few checks for if player is connected, and a few proper lvl checks, you may change this to your preferences if you wish.
pawn Code:
CMD:setlevel(playerid, params[])
{
if(PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Your not a admin");
new id, lvl, string[128];
if(sscanf(params,"ui",id,lvl)) return SendClientMessage(playerid, -1, "USAGE: /setlevel <id> <lvl>");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Invalid playerid");
if(lvl < 1 || lvl > PlayerInfo[playerid][Padmin] && PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Invalid level");
format(string, sizeof(string), "You have set %s admin level to %d", PlayerName(id), lvl);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Your level has been set to %d by %s", lvl, PlayerName(playerid));
SendClientMessage(id, -1, string);
format(string, sizeof(string), "%s is now admin level %d", PlayerName(id), lvl);
SendClientMessageToAll(-1, string);
PlayerInfo[id][Padmin] = lvl;
return 1;
}