SA-MP Forums Archive
[Tutorial] [TUT]Admin Only Command for anything!! - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] [TUT]Admin Only Command for anything!! (/showthread.php?tid=90925)



[TUT]Admin Only Command for anything!! - DEJORDZTA - 11.08.2009

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!!!!






Re: [TUT]Admin Only Command for anything!! - CracK - 11.08.2009

This is better than your 1000000000000 health:
pawn Code:
#define INFINITY (Float:0x7F800000)
SetPlayerHealth(playerid, INFINITY);



Re: [TUT]Admin Only Command for anything!! - DarkClone - 11.08.2009

Nice little tut , maybe use [ code ] [ / code ] (without spaces) tags for the commands it would be easier


Re: [TUT]Admin Only Command for anything!! - ruarai - 11.08.2009

Quote:
Originally Posted by CrαcK
This is better than your 1000000000000 health:
pawn Code:
#define INFINITY (Float:0x7F800000)
SetPlayerHealth(playerid, INFINITY);
setting the players health to that actualy kills them


Re: [TUT]Admin Only Command for anything!! - Joe Staff - 11.08.2009

It can only go up to 0x7FFFFFFF which is 2147483647, but you know, 100000 is a lot too.


Re: [TUT]Admin Only Command for anything!! - CracK - 11.08.2009

http://forum.sa-mp.com/index.php?top...4411#msg424411


Re: [TUT]Admin Only Command for anything!! - Joe Staff - 11.08.2009

Alright fine, you set your people's health to Infinity by IEEE standards ^.^

It doesn't need to be infinity, just needs to be enough so the person won't die... anytime today.


Re: [TUT]Admin Only Command for anything!! - Woet - 11.08.2009

Can be way simpler:
Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "This command can only be used by an admin!!");
Original code:
Code:
if (strcmp("/cctv", cmdtext, true) == 0)
{
  PlayerMenu[playerid] = 0;
  TogglePlayerControllable(playerid, 0);
  ShowMenuForPlayer(CCTVMenu[0], playerid);
  return 1;
}
Admin only:
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;
}
Saves a lot of code, saves messing with brackets/indentation and is simply cleaner.


Re: [TUT]Admin Only Command for anything!! - CracK - 11.08.2009

Quote:
Originally Posted by Joe Staff
Alright fine, you set your people's health to Infinity by IEEE standards ^.^

It doesn't need to be infinity, just needs to be enough so the person won't die... anytime today.
Ok, ok SetPlayerHealth(playerid, INFINITY); just looks neater.
Also instead of:
pawn Code:
if (strcmp("/cctv", cmdtext, true) == 0)
This:
pawn Code:
if (!strcmp("/cctv", cmdtext, true))
Both work


Re: [TUT]Admin Only Command for anything!! - Burridge - 11.08.2009

There is only one problem with this. Yes it works perfectly. But, what if people use a admin FS of somekind? Or an account system? This will set it so you have to be logged into RCON. So yes this is good for people who use RCON to admin their server, but if you use a account system/admin FS, you'll want to change the "IsPlayerAdmin" line, to somthing that suits your account system, EG: SeifAdmin uses AccountInfo (Aswell as many others) so for that admin FS you'd have to use, "if(AccountInfo[playerid][AdminLevel] >= 1). Just a heads up.