Help with /makeadmin command.
#1

Hello, i have attempted to make a /makeadmin command, however when i try to use it, no matter what id i use, it always gives me a message saying i have promoted myself to level 0 and takes my admin privelages away. I am not sure what is causing the problem.

Here is the command script.

dcmd_makeadmin(playerid, params[])
{
if(Player[playerid][level] == 4 || IsPlayerAdmin(playerid)) {}
new pID,alevel;
if(Player[playerid][level] < 4){
return SendClientMessage(playerid, COLOR_RED, "You must be admin level 4 to do this!");
}
else if(!strlen(params)){
return SendClientMessage (playerid,COLOR_RED,"USAGE: /makeadmin [playerid] [adminlevel]");
}
else if(!IsPlayerConnected(pID)){
return SendClientMessage (playerid,COLOR_RED,"Nobody is connected with this ID!");
}
else
{
new string[128],string2[128],aname[MAX_PLAYER_NAME],name[MAX_PLAYER_NAME];
Player[pID][level] = alevel;
GetPlayerName(playerid,aname,sizeof(aname));
GetPlayerName(pID,name,sizeof(name));
format(string,sizeof(string),"You have set the admin level of %s to %d",name,alevel);
format(string2,sizeof(string2),"ServerOwner %s has set your admin level to %d",aname,alevel);
SendClientMessage(playerid,COLOR_GREEN,string);
SendClientMessage(pID,COLOR_GREEN,string2);
return 1;
}
}
Reply
#2

You haven't defined the id which the level will be give for ( I mean params ). Try this code:
pawn Код:
dcmd_makeadmin(playerid, params[])
{
if(Player[playerid][level] == 4 || IsPlayerAdmin(playerid)) {}
new pID,alevel;
new tmp[256], tmp2[256], Index;     tmp = strtok(params,Index), tmp2 = strtok(params,Index);
pID = strval(tmp);
alevel = strval(tmp2);
if(Player[playerid][level] < 4){
return SendClientMessage(playerid, COLOR_RED, "You must be admin level 4 to do this!");
}
else if(!strlen(tmp) || !strlen(tmp2)){
return SendClientMessage (playerid,COLOR_RED,"USAGE: /makeadmin [playerid] [adminlevel]");
}
else if(!IsPlayerConnected(pID)){
return SendClientMessage (playerid,COLOR_RED,"Nobody is connected with this ID!");
}
else
{
new string[128],string2[128],aname[MAX_PLAYER_NAME],name[MAX_PLAYER_NAME];
Player[pID][level] = alevel;
GetPlayerName(playerid,aname,sizeof(aname));
GetPlayerName(pID,name,sizeof(name));
format(string,sizeof(string),"You have set the admin level of %s to %d",name,alevel);
format(string2,sizeof(string2),"ServerOwner %s has set your admin level to %d",aname,alevel);
SendClientMessage(playerid,COLOR_GREEN,string);
SendClientMessage(pID,COLOR_GREEN,string2);
return 1;
}
}
May work
Reply
#3

okay, now when i use that if the id is not valid it bring up the message saying that it isn't valid, but if i try to make my friend an admin i get the message saying i have promoted myself to admin.
Reply
#4

try this... with sscanf...
pawn Код:
dcmd_makeadmin(playerid, params[])
{
if(Player[playerid][level] < 4 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"Must be admin level 4");
new pID,alevel;
if(sscanf(params,"ii",pID,alevel)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /makeadmin id level");
if(!IsPlayerConnected(pID)) return SendClientMessage (playerid,COLOR_RED,"Nobody is connected with this ID!");
new string[128],string2[128],aname[MAX_PLAYER_NAME],name[MAX_PLAYER_NAME];
Player[pID][level] = alevel;
GetPlayerName(playerid,aname,sizeof(aname));
GetPlayerName(pID,name,sizeof(name));
format(string,sizeof(string),"You have set the admin level of %s to %d",name,alevel);
format(string2,sizeof(string2),"ServerOwner %s has set your admin level to %d",aname,alevel);
SendClientMessage(playerid,COLOR_GREEN,string);
SendClientMessage(pID,COLOR_GREEN,string2);
return 1;
}
Reply
#5

XePloit that did work, thanks a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)