[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


Messages In This Thread
How to make a basic admin command. - by Lorenc_ - 02.11.2010, 05:21
Re: How to make a basic admin command. - by MBX97 - 02.11.2010, 21:30
Re: How to make a basic admin command. - by Bessensap - 02.11.2010, 22:27
Re: How to make a basic admin command. - by zSuYaNw - 03.11.2010, 13:46
Re: How to make a basic admin command. - by HyperZ - 03.11.2010, 14:42
Re: How to make a basic admin command. - by hadzx - 03.11.2010, 14:43
Re: How to make a basic admin command. - by Hiddos - 03.11.2010, 20:14
Re: How to make a basic admin command. - by Lorenc_ - 04.11.2010, 05:34
Re: How to make a basic admin command. - by blackwave - 04.11.2010, 21:10
Re: How to make a basic admin command. - by Kwarde - 05.11.2010, 15:17

Forum Jump:


Users browsing this thread: 1 Guest(s)