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

You could have done this tutorial better because, in this case, you use the teams. Unfortunately, you should have explained what is the FULL procedure of doing a team (I'm talking about team colours, OnPlayerRequestClass and so) so new scripters could have actually said what you've explained is helpful.
Reply
#3

Quote:
Originally Posted by HeLLeR
View Post
You could have done this tutorial better because, in this case, you use the teams. Unfortunately, you should have explained what is the FULL procedure of doing a team (I'm talking about team colours, OnPlayerRequestClass and so) so new scripters could have actually said what you've explained is helpful.
This tutorial isn't about the teams, it's about giving certain players access to commands. If I was doing a tutorial on how to set up teams, I would have explained all of that, but I wasn't. As I clearly stated at the top, this is only about giving certain players access to commands. Like cop commands.
Reply
#4

Quote:
Originally Posted by Ciarannn
View Post
This tutorial isn't about the teams, it's about giving certain players access to commands. If I was doing a tutorial on how to set up teams, I would have explained all of that, but I wasn't. As I clearly stated at the top, this is only about giving certain players access to commands. Like cop commands.
I understand your point, but mine was that you should have explained how to do teams so new scripters could have used it with ease. In other words, players also need to spawn in a team, do they? What if a scripter does not know how to make them spawn? That's why I suggested to explain that too
Reply
#5

Quote:
Originally Posted by HeLLeR
View Post
I understand your point, but mine was that you should have explained how to do teams so new scripters could have used it with ease. In other words, players also need to spawn in a team, do they? What if a scripter does not know how to make them spawn? That's why I suggested to explain that too
I suppose so. I will link a tutorial on how to do that.
Reply
#6

Thanks.
Reply
#7

You should have used zcmd or any other command processor, nice tutorial though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)