[Tutorial] How to make a basic admin command.
#1

After seeing quite a lot of people asking me about this i decided to make a tutorial for not only them but for every other person that has no clue how to.

Ok, lets get started.

Most you people have enums for storing items in one variable, well your going to need that, or some variable.

Code:
enum pInfo
{
    pAdminLevel,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
^^ like that (Enum's)

Single variables:

Code:
new IsAdmin[MAX_PLAYERS];
Now simply you can use any of those to create a admin command.
(In this instance ill use DCMD)
(Borrowed code of the wiki)

Making a heal command but only avaible for admins.

Code:
 
dcmd_heal(playerid, params[])
{
	new
		id;
	if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
	else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else
	{
		SetPlayerHealth(id, 100.0);
		SendClientMessage(id, 0x00FF00AA, "You have been healed");
		SendClientMessage(playerid, 0x00FF00AA, "Player healed");
	}
	return 1;
}
Thats plain and just for regular players. To simply make it for admins create a if statement and insert the variable.

E.G

Code:
if(IsAdmin[playerid] == 3)
^^ if the admin is level 3 then enable it
Insert it here

Code:
dcmd_heal(playerid, params[])
{
//*** Here ***
So your admin command should turn out to be like this:

Code:
dcmd_heal(playerid, params[])
{
        if(IsAdmin[playerid] == 3){
	new
		id;
	if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
	else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else
	{
		SetPlayerHealth(id, 100.0);
		SendClientMessage(id, 0x00FF00AA, "You have been healed");
		SendClientMessage(playerid, 0x00FF00AA, "Player healed");
	}
        }
	return 1;
}
To add a msg when the player uses the command without being admin create a else.

Code:
dcmd_heal(playerid, params[])
{
        if(IsAdmin[playerid] == 3){
	new
		id;
	if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
	else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else
	{
		SetPlayerHealth(id, 100.0);
		SendClientMessage(id, 0x00FF00AA, "You have been healed");
		SendClientMessage(playerid, 0x00FF00AA, "Player healed");
	}
        }else{
                SendClientMessage(playerid, 0x00FF00AA, "Your not admin (LEVEL 3)");
        }
	return 1;
}
Ok, thats it. Now you should relise its simple!
Soz for awful editing in a rush D:

-Lorenc
Reply
#2

cool and i like to be your first replay so AWESOME man and keep up the gud work
pawn Code:
new MBX[ MAX_WHORES ];
Reply
#3

Quote:
Originally Posted by MBX97
View Post
cool and i like to be your first replay so AWESOME man and keep up the gud work
pawn Code:
new MBX[ MAX_WHORES ];
whats with the new MBX[MAX_WHORES]; ?
trying to look cool with someone else's (don't remember who's atm) actual script?
Please, don't
[/offtopic]

Gud tut Lorenc, will def. help out some noobies ;p
Reply
#4

Or
pawn Code:
if(IsPlayerAdmin(playerid)) return 0;
Ps, Very Good Tut's.
Reply
#5

Great TUT
Reply
#6

good tut
Reply
#7

Quote:
Originally Posted by [Full]Garfield[XDB]
View Post
Or
pawn Code:
if(IsPlayerAdmin(playerid)) return 0;
Ps, Very Good Tut's.
What is mostly based on the RCON admin, however would still provide useful.

Good tut, thanks for focusing on really the admin part, and not how to make people admin or how to save admin status and crap as that is really useless in this topic, you just kept on-topic all the time. Good job, I'm sure some people would like it ^^
Reply
#8

Thank you all, man i just hate the worthless posts around here. They should cut down only if they look in the tutorials sub-forum. Thanks!

Quote:
Originally Posted by [Full]Garfield[XDB]
View Post
Or
pawn Code:
if(IsPlayerAdmin(playerid)) return 0;
Ps, Very Good Tut's.
yeah you can do that too!
Reply
#9

Hehe, very nice. I forgot where to find this command, such as: "/kill playerID"

Now I found, thx
Reply
#10

Quote:
Originally Posted by [Full]Garfield[XDB]
View Post
Or
pawn Code:
if(IsPlayerAdmin(playerid)) return 0;
Ps, Very Good Tut's.
So that means, that if a player is logged in as RCON, he can't use the command: return 0;
Don't you mean

pawn Code:
if(IsPlayerAdmin(playerid)){
//code
}else return 0;
Or

pawn Code:
if(!IsPlayerAdmin(playerid)) return 0;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)