Admin restrict a command
#1

I'm new to scripting and I want to know how to restrict a cmd.
In our roleplay server we got admin ranks. 1,2,3,4,1337,1338,99999
I want to restrict a cmd for a lvl 4+ admins. How to do that?
Note: I don't want a code that checks the player if he is a RCON admin. I just want a script to restrict for IG admins lvl 4+. Not RCON admins.
Reply
#2

Well i'll predict your script
pawn Код:
If(PlayerInfo[playerid][pAdmin] >= 4)
{
//Code
}
Reply
#3

What is that? Where to put the cmd? Where is the error text?
Reply
#4

It would've been nice if you provided the admin system you're using, but still, the logic works this way:
  • Player issues a command
  • You check his level
  • If it's 4 or bigger than 4, success
  • If his level is less than 4 you display your error message
Код:
  
if(playerinfo[playerid][alevel] >= 4)  
{
    // Success.... 
}  
else if(playerinfo[playerid][alevel] < 4)
{
    // Something like "You can't use the command specified."
}
Reply
#5

Aigh't explained well, but can you show me the coding of let's say I wanna restrict the cmd. /kick to a level 2 admin. Because it is very hard to understand your example.
Reply
#6

Quote:
pawn Код:
if(playerinfo[playerid][alevel] >= 2)  //This is admin level required to use an command.
{
    // Success....
}  
else if(playerinfo[playerid][alevel] < 2) //That command can be used only by admin level 2+
{
    // Something like "You can't use the command specified."
}
-Edited from Kurzalewski's example.
Reply
#7

Where to I put the command?
Reply
#8

To "/kick" command, as you said.
Reply
#9

Yes, but where do I put " /kick " in those codeS? I don't see you typing /kick in between them.
Reply
#10

Here you are a working command:
pawn Код:
CMD:kick(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
        new str[128], reason[64], targetid;
        if(sscanf(params,"us", targetid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /kick [Player ID] [Reason]");
        {
            if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "SERVER: Player not connected");

            SendClientMessageToAll(COLOR_RED, str);
            Kick(targetid);
        }
    }
    else SendClientMessage(playerid, COLOR_RED, "You do not have access to this command!");
    return 1;
}
NOTE: Make sure that you have sscanf and zcmd includes.
Define this on top of your script:
pawn Код:
#define C_WHITE     0xFFFFFFFF
#define COLOR_RED  0xFF0000FF
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)