26.02.2015, 01:10
I just finish coding this /setadmin command into my gamemode, it is working but has one problem.
When I setting player's admin level from 1-2 this code won't work / appear in chat ......
When I setting player's admin level from 1-2 this code won't work / appear in chat ......
pawn Код:
new string[200];
format(string, sizeof(string), ""COLOR_ADMIN"[ADMIN CHAT]: %s has promoted %s to a level %d administrator.", GetPlayerRPName(playerid), GetPlayerRPName(targetid), adminlevel);
SendAdminMessage(-1, string);
pawn Код:
YCMD:setadmin(playerid, params[], help)
{
new targetid, adminlevel;
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 5)
{
if(sscanf(params, "ri", targetid, adminlevel))
{
SendClientMessage(playerid, -1, ""COLOR_GRAY"[USAGE]: /setadmin [ID] [Level]");
return 1;
}
else if(adminlevel < 0 || adminlevel > 5)
{
SendClientMessage(playerid, -1, ""COLOR_SERVER"SERVER: You can only set admin levels from 0-5.");
return 1;
}
else if(targetid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, -1, ""COLOR_SERVER"SERVER: Player is not connected to the server.");
return 1;
}/*
else if(PlayerInfo[targetid][pAdmin] == 5)
{
SendClientMessage(playerid, -1, ""COLOR_SERVER"SERVER: You need RCON access to perform this action.");
return 1;
}*/
else
{
if(adminlevel == 0)
{
if(PlayerInfo[targetid][pAdmin] < 1)
{
SendClientMessage(playerid, -1, ""COLOR_SERVER"SERVER: This player is not an administrator.");
return 1;
}
else
{
new string[128];
PlayerInfo[targetid][pAdmin] = adminlevel;
format(string, sizeof(string), ""COLOR_ADMIN"[ADMIN CHAT]: %s has been removed %s from the administrator team.", GetPlayerRPName(playerid), GetPlayerRPName(targetid));
SendAdminMessage(-1, string);
SendClientMessage(playerid, -1, "You have been removed from the administrator team.");
return 1;
}
}/*
else if(playerid == targetid)
{
new string[128];
format(string, sizeof(string), "You have made yourself a level %d administrator.", adminlevel);
SendClientMessage(playerid, -1, string);
PlayerInfo[targetid][pAdmin] = adminlevel;
return 1;
}*/
else if(adminlevel > PlayerInfo[targetid][pAdmin])
{
new string[200];
format(string, sizeof(string), ""COLOR_ADMIN"[ADMIN CHAT]: %s has promoted %s to a level %d administrator.", GetPlayerRPName(playerid), GetPlayerRPName(targetid), adminlevel);
SendAdminMessage(-1, string); // Problem, won't appear in-chat when setting levels 1-2.
format(string, sizeof(string), ""COLOR_GREEN"You have been promoted to a level %d administrator by %s.", adminlevel, GetPlayerRPName(playerid));
SendClientMessage(targetid, -1, string);
format(string, sizeof(string), ""COLOR_GREEN"You have promoted %s to a level %d administrator.", GetPlayerRPName(targetid), adminlevel);
SendClientMessage(playerid, -1, string);
PlayerInfo[targetid][pAdmin] = adminlevel;
return 1;
}
else if(adminlevel < PlayerInfo[targetid][pAdmin])
{
new string[200];
format(string, sizeof(string), ""COLOR_ADMIN"[ADMIN CHAT]: %s has demoted %s to a level %d administrator.", GetPlayerRPName(playerid), GetPlayerRPName(targetid), adminlevel);
SendAdminMessage(-1, string);
format(string, sizeof(string), ""COLOR_GREEN"You have been demoted to a level %d administrator by %s.", adminlevel, GetPlayerRPName(playerid));
SendClientMessage(targetid, -1, string);
format(string, sizeof(string), ""COLOR_GREEN"You have demoted %s to a level %d administrator.", GetPlayerRPName(targetid), adminlevel);
SendClientMessage(playerid, -1, string);
PlayerInfo[targetid][pAdmin] = adminlevel;
return 1;
}
}
}
else return SendClientMessage(playerid, -1, ""COLOR_SERVER"SERVER: You are not authorized to use this command.");
return 1;
}