[Tutorial] [TUT]Admin Only Command for anything!!
#1

Hey guys,

Dunno whether this has already been posted but i've got a tutorial for the newbs, like me, out there who want to know how to make a command admin only!!

It's really simple!

first of all, lets say i want to use the awesome CCTV camera script (made by =>Sandra<=! !!!), and make that an admin only command......

ok so this is the code that when you type /cctv in sa-mp it comes up with the menu.....


Code:
if (strcmp("/cctv", cmdtext, true) == 0)
{
  PlayerMenu[playerid] = 0;
  TogglePlayerControllable(playerid, 0);
  ShowMenuForPlayer(CCTVMenu[0], playerid);
  return 1;
}
but we could use any code..... any way what we would do is this.....

Code:
{
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "This command can only be used by an admin!!");
we would add that above the :

Code:
  PlayerMenu[playerid] = 0;
part, so we had this for our code...
Code:
if (strcmp("/cctv", cmdtext, true) == 0)

  {
    PlayerMenu[playerid] = 0;
    TogglePlayerControllable(playerid, 0);
    ShowMenuForPlayer(CCTVMenu[0], playerid);
    return 1; 
  }
}


But with the line (above) added in we should know have this for our code....


Code:
if (strcmp("/cctv", cmdtext, true) == 0)

{
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "This command can only be used by an admin!!");

  PlayerMenu[playerid] = 0;
  TogglePlayerControllable(playerid, 0);
  ShowMenuForPlayer(CCTVMenu[0], playerid);
  return 1;
}
[color=blue]
NOTE!! Instead of :
Code:
'if (strcmp("/cctv", cmdtext, true) == 0)'
we could have
Code:
'if (!strcmp("/cctv", cmdtext, true))'
if you want it to be shorter as both work.
AGAIN!! this can be used for any command, like a tele! just add:

Code:
{
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "This command can only be used by an admin!!");
[color=blue]above the code you want to make admin's only

E.G

From this......
Code:
	if (strcmp("/godmode", cmdtext, true, 10) == 0)
	{
	SendClientMessageToAll(0xDEEE20FF, "A Player Used God Mode [/god]");
 	SetPlayerHealth(playerid, 1000000000000000000000000000000000000000000000.0);
	return 1;
	}

So we get......

Code:
	
if (strcmp("/cctv", cmdtext, true) == 0)
{
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "This command can only be used by an admin!!");

  PlayerMenu[playerid] = 0;
  TogglePlayerControllable(playerid, 0);
  ShowMenuForPlayer(CCTVMenu[0], playerid);
  return 1;
}

I Hope this makes sense and that it helped you!!!!



Reply


Messages In This Thread
[TUT]Admin Only Command for anything!! - by DEJORDZTA - 11.08.2009, 06:08
Re: [TUT]Admin Only Command for anything!! - by CracK - 11.08.2009, 06:11
Re: [TUT]Admin Only Command for anything!! - by DarkClone - 11.08.2009, 06:14
Re: [TUT]Admin Only Command for anything!! - by ruarai - 11.08.2009, 06:29
Re: [TUT]Admin Only Command for anything!! - by Joe Staff - 11.08.2009, 06:32
Re: [TUT]Admin Only Command for anything!! - by CracK - 11.08.2009, 06:46
Re: [TUT]Admin Only Command for anything!! - by Joe Staff - 11.08.2009, 06:48
Re: [TUT]Admin Only Command for anything!! - by Woet - 11.08.2009, 07:26
Re: [TUT]Admin Only Command for anything!! - by CracK - 11.08.2009, 08:59
Re: [TUT]Admin Only Command for anything!! - by Burridge - 11.08.2009, 14:46

Forum Jump:


Users browsing this thread: 1 Guest(s)