How do i put a command for admin only?
#1

Hello all, i was just wondering how to make a command for admins only,
i have this command for example:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true, 10) == 0)
        {
    SetPlayerHealth(playerid,100);// heal the player
    SendClientMessage(playerid, COLOR_YELLOW, "FT Bot: "#COL_GREEN"You have been healed!");
    return 1;
    }
    return 0;
}
Now, i would like /heal to be for admins only. I appreciate your help!
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true, 10) == 0)
    {
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not an Admin!");
        SetPlayerHealth(playerid,100);// heal the player
        SendClientMessage(playerid, COLOR_YELLOW, "FT Bot: "#COL_GREEN"You have been healed!");
        return 1;
    }
    return 0;
}
Reply
#3

If your using RCON admin us

pawn Код:
if(IsPlayerAdmin(playerid));
If your using your own system use your arraay

Example
pawn Код:
if(PlayerInfo[playerid][pAdmin]);
or dont try to learn and use your Premade code above ^ with no explanation
Reply
#4

First of all, why do you specify a length in strcmp? It seems a little odd considering it doesn't do anything in this circumstance.

Secondly, how do you want to check for administrator? Do you want to use the standard RCON administrator stuff? If so, then use IsPlayerAdmin, for example:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true) == 0)
    {
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You need to be RCON admin!"); // Check if the player is not an RCON admin and stop execution with a client message
        SetPlayerHealth(playerid,100);// heal the player
        SendClientMessage(playerid, COLOR_YELLOW, "FT Bot: "#COL_GREEN"You have been healed!");
        return 1;
    }
    return 0;
}
You can read more about IsPlayerAdmin on the SA-MP Wiki:

https://sampwiki.blast.hk/wiki/IsPlayerAdmin

Edit: grr, stop posting so fast!
Reply
#5

Haha yeah, it's going fast indeed.
i wanted to make it available for Admins, not for rcon.
Thanks guys for your help
Reply
#6

You need to create a login + register system wich is saving the Adminlevel, so you can call that at some commands.
Reply
#7

https://sampforum.blast.hk/showthread.php?tid=273088

Follow this tutorial and you should learn how to create a save system

Once that is done to check for a admin do

pawn Код:
if(PlayerInfo[playerid][pAdmin]);
Instead of using if(IsPlayerAdmin(playerid));

EDIT Expanding on what he said above ^
Reply
#8

Thanks!
Reply
#9

*bump* sorry for double post but, i still didn't manage to figure out how i put he admin command, because i use a GM called PPC_Trucking by powerpc603. I dont know what system he uses, i asked him but i still have no answer. so i was wondering does anyone know how i put a command as admin only for THAT GM, thanks!
link to his thread: https://sampforum.blast.hk/showthread.php?tid=196493
Reply
#10

If im right, the GM is using "APlayerData[playerid][PlayerLevel]".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)