SA-MP Forums Archive
[Tutorial] How to make a basic admin command. - 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] How to make a basic admin command. (/showthread.php?tid=187294)



How to make a basic admin command. - Lorenc_ - 02.11.2010

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



Re: How to make a basic admin command. - MBX97 - 02.11.2010

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



Re: How to make a basic admin command. - Bessensap - 02.11.2010

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


Re: How to make a basic admin command. - zSuYaNw - 03.11.2010

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


Re: How to make a basic admin command. - HyperZ - 03.11.2010

Great TUT


Re: How to make a basic admin command. - hadzx - 03.11.2010

good tut


Re: How to make a basic admin command. - Hiddos - 03.11.2010

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


Re: How to make a basic admin command. - Lorenc_ - 04.11.2010

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!


Re: How to make a basic admin command. - blackwave - 04.11.2010

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

Now I found, thx


Re: How to make a basic admin command. - Kwarde - 05.11.2010

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;