[Tutorial] Giving Only Certain Players Access to Commands
#1

Like the title says, this is a tutorial on how to give only certain players commands. Like an admin command, only admins can use it. Lets get started.

Here are the main things we will be using today:

Code:
new gTeam[MAX_PLAYERS]; //Making teams

#define [TEAM NAME] 1 //Defining your team

gTeam[playerid] = [TEAM NAME]; //Setting a player to that team

if(gTeam[playerid] == [TEAM NAME]) // checking if a player is on that team, to give him access to the CMD.
Ok, so now making the commands and stuff. I will just make a command for lets say a Cop team.
To start, under the #endif at the top of your script, type:

Code:
new gTeam[MAX_PLAYERS]; //Creating the team function
#define TEAM_COP 1 //Defining your team, the "1" is there to define the team number.
Now that we have defined our team, we need to make a command for the cops like giving them armour. ((This is highly un-roleplay like, but for the purpose of the tutorial I'm just using it.))

Making the command:

Code:
if (strcmp("/coparmour", cmdtext, true, 10) == 0)
{
	if(gTeam[playerid] == TEAM_COP) {
	SendClientMessage(playerid, 0,"You have been given full armour.");
	SetPlayerArmour(playerid, 100.0);
	return 1; }
}
Explaining time:
The command below, is a simple strcmp command that you type to activate the command you set. (Giving armour.))

Code:
if (strcmp("/coparmour", cmdtext, true, 10) == 0)
Next, this command will check if the player is on that team, scroll down for information on setting them to that team.
Code:
if(gTeam[playerid] == TEAM_COP) { //Don't forget the "{" after or this won't work.
Now to do whatever command you wan't like giving the player armour:
Code:
SendClientMessage(playerid, 0,"You have been given full armour."); //Sends the player a message saying he has been given full armour.

SetPlayerArmour(playerid, 100.0); //Set the players armour to 100%.
Then you need to end the command by typing:
Code:
return 1; }  //Make sure you have the "}" to close the above one after "if(gTeam[playerid] == TEAM_COP) {".
Ok, so now we need to know how to set that players team:
Code:
if (strcmp("/setcop", cmdtext, true, 10) == 0)
	{
	gTeam[playerid] = TEAM_COP;
	SendClientMessage(playerid, 0, "You have set yourself to be a cop.");
	return 1;
	}
Explaining:
This code will set the players team to the cops, if you wan't to set another players team to cops, you need to use ZCMD or another third party code. You can ****** ZCMD Tutorial, and I'm sure you will get some results.

Code:
gTeam[playerid] = TEAM_COP;
The rest has already been explained above.

If you want to return an error message to a player that is trying to use the command but isn't a cop, this is how you do it:

Code:
Above where you defined the Cops team, you need to ad:

#define TEAM_COP 1 //You should already have this.
#define TEAM_NORMAL 2 //Add this below the cop define
Then you need to put under you armour command:

Code:
if (strcmp("/coparmour", cmdtext, true, 10) == 0)
{
	if(gTeam[playerid] == TEAM_COP) {
	SendClientMessage(playerid, 0,"You have been given full armour.");
	SetPlayerArmour(playerid, 100.0);
	return 1; }

	if(gTeam[playerid] == TEAM_NORMAL) { //This will check if the players team is normal.
	SendClientMessage(playerid, 0xFFFFFFAA, "Only cops can use this command."); // <-- Tells them that. 
	return 1; }
}
You might want to add this into your script:

Code:
public OnPlayerConnect(playerid) //Under this in your script, add the code below.
{
	gTeam[playerid] = TEAM_NORMAL;
	return 1;
}
You would then have to have an Cop login command, so they can sign in as a cop.

For more information on how to make teams, and spawn players, with custom chat colours, please take a look at this tutorial.
Reply


Messages In This Thread
Giving Only Certain Players Access to Commands - by Ciarannn - 16.03.2014, 14:12
Re: Giving Only Certain Players Access to Commands - by HeLLeR - 16.03.2014, 14:17
Re: Giving Only Certain Players Access to Commands - by Ciarannn - 16.03.2014, 14:20
Re: Giving Only Certain Players Access to Commands - by HeLLeR - 16.03.2014, 14:30
Re: Giving Only Certain Players Access to Commands - by Ciarannn - 16.03.2014, 14:32
Re: Giving Only Certain Players Access to Commands - by Ciarannn - 16.03.2014, 14:43
Re: Giving Only Certain Players Access to Commands - by Jimmy0wns - 21.03.2014, 11:16

Forum Jump:


Users browsing this thread: 1 Guest(s)