[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
#2

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

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

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
Reply
#5

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

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

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.
Reply
#8

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.
Reply
#9

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
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)