[Question] How to make an Admin command
#1

Hey its me again for like the 3rd time in one day.. lol
anyway i was wondering how do u make an a command that only admins can use?
for example a teleport:

Код:
if (strcmp("/ls", cmdtext, true, 10) == 0)
	{
    SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
    SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
    new name[MAX_PLAYER_NAME], string[100];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
    SendClientMessageToAll(COLOR_LIGHTBLUE, string);
	return 1;
Reply
#2

if (strcmp("/ls", cmdtext, true, 10) == 0)
{
IsPlayerAdmin(playerid))
{
SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
new name[MAX_PLAYER_NAME], string[100];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
SendClientMessageToAll(COLOR_LIGHTBLUE, string);
return 1;
}

I think If its wrong, Ill fix
Reply
#3

use this : (State_Trooper u forgot "if")
Код:
if(strcmp("/ls", cmdtext, true, 10) == 0)
  {
   if(IsPlayerAdmin(playerid))
   {
    SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
    SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
    new name[MAX_PLAYER_NAME], string[100];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
    SendClientMessageToAll(COLOR_LIGHTBLUE, string);
    else { SendClientMessage(playerid,COLOR_LIGHTBLUE,"You Aren't Admin"); }
  return 1;
}
Reply
#4

i did what you said and it gave me crap loads of errors so i did this but it says im not admin when i try the tele...
Код:
	if(strcmp(cmdtext, "/adminship", true) == 0)
	{
 	  if(IsPlayerAdmin(playerid))

     SetPlayerPos(playerid, 3203.9760,-1472.5383,16.6099);
     else SendClientMessage(playerid,COLOR_LIGHTBLUE,"You not admin, are you retarded?!");
    return 1;
Reply
#5

pawn Код:
if (strcmp("/ls", cmdtext, true, 3) == 0)
    {
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR, "Admins Only!");
        else
        SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
        SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
        new name[MAX_PLAYER_NAME], string[100];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
        SendClientMessageToAll(COLOR_LIGHTBLUE, string);
        return 1;
    }
Reply
#6

That will work Garsino, but the 'else' is pointless. Not only will it only run the first command following it, but if the player isn't admin it will stop the command anyway.

pawn Код:
if (strcmp("/ls", cmdtext, true, 3) == 0)
{
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR, "Admins Only!");
  SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
  SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
  new name[MAX_PLAYER_NAME], string[100];
  GetPlayerName(playerid, name, sizeof(name));
  format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
  SendClientMessageToAll(COLOR_LIGHTBLUE, string);
  return 1;
}
Reply
#7

aww man! it still says im not admin! does it only work if your logged in rcon or something?
I rly need to make this admin only because it would suck if players could just enter admin village and take all the weapons lol

Код:
if(strcmp(cmdtext, "/adminship", true, 10) == 0)
	{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "Your not admin!");
    SetPlayerPos(playerid, 3203.9760,-1472.5383,16.6099);
    return 1;
Reply
#8

If you use GF GameMode

You should use PlayerInfo[playerid][pAdmin]
pawn Код:
if (strcmp("/ls", cmdtext, true, 3) == 0)
{
   if(PlayerInfo[playerid][pAdmin] > 1)
  {  
    SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
    SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
    new name[MAX_PLAYER_NAME], string[100];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
    SendClientMessageToAll(COLOR_LIGHTBLUE, string);
  }
  else
  {
   SendClientMessage(playerid, COLOR, "Admins Only!");
   }
  return 1;
}
Sorry for my lame English
Reply
#9

yeah i dont use this 'gf' gamemode so i really dont know what to do here

Reply
#10

Код:
if (strcmp("/ls", cmdtext, true, 10) == 0)
{
if(IsPlayerAdmin(playerid))
{
SetPlayerPos(playerid, 1544.4379,-1353.2231,329.4744);
SendClientMessage(playerid, COLOR_YELLOW, "Welcome to Los Santos!");
new name[MAX_PLAYER_NAME], string[100];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "[TELEPORT] %s has gone to Los Santos [/ls]", name );
SendClientMessageToAll(COLOR_LIGHTBLUE, string);
return 1;
}
SendClientMessage(playerid, COLOR_RED, "ERROR: You are not an admin!");
return 1;
}
There you go.

the command only works for rcon admins
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)