Command Restriction - 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: Command Restriction (
/showthread.php?tid=613245)
Command Restriction -
yvoms - 26.07.2016
I've created a kick command
Код:
CMD:kick(playerid,params[])
{
new id, aname[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], Reason[128], string[128];
if(pData[playerid][Admin] < 2) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command.");
if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command on a higher level administrator.");
if(id == playerid) return SendClientMessage(playerid, COLOR_WHITE,"[Error]: You can not perform this command on yourself.");
if(sscanf(params,"us[128]",id, Reason)) return SendClientMessage(playerid,-1,"[Admin]: /kick [ID | Name] [Reason]");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,-1,"[Error]: This player is not connected.");
{
GetPlayerName(playerid, aname, sizeof(aname));
GetPlayerName(id, name, sizeof(name));
format(string,sizeof (string),"[Admin]: %s(%d) Has kicked player: %s(%d) Reason : %s", aname, playerid, name, id, Reason);
SendClientMessageToAll(COLOR_WHITE, string);
Kick(id);
}
return 1;
}
However i'm a level 6 admin, and a level 5 admin is able to kick me even when i have the line added.
if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command on a higher level administrator.");
Did i make a mistake or, could u please explain what im doing wrong, as i have this at all my commands :3
Re: Command Restriction -
ThePhenix - 26.07.2016
That's not the correct order, it should be:
PHP код:
CMD:kick(playerid,params[])
{
new id, aname[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], Reason[128], string[128];
if(pData[playerid][Admin] < 2) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command.");
//First sscanf
if(sscanf(params,"us[128]",id, Reason)) return SendClientMessage(playerid,-1,"[Admin]: /kick [ID | Name] [Reason]");
if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command on a higher level administrator.");
if(id == playerid) return SendClientMessage(playerid, COLOR_WHITE,"[Error]: You can not perform this command on yourself.");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,-1,"[Error]: This player is not connected.");
{
GetPlayerName(playerid, aname, sizeof(aname));
GetPlayerName(id, name, sizeof(name));
format(string,sizeof (string),"[Admin]: %s(%d) Has kicked player: %s(%d) Reason : %s", aname, playerid, name, id, Reason);
SendClientMessageToAll(COLOR_WHITE, string);
Kick(id);
}
return 1;
}
You are declaring a variable called "id" however you were always doing the check for the ID 0 as the variable "id" was not yet set during that check.