10.11.2009, 23:44
Teams In SA:MP
Over the last few days I have seen an abundance in Team related topics. Some of which asking the same question. I'm using some knowledge I've picked up to make this tutorial to help anyone who wants to make teams in any game mode. This is not a copy and paste script, it's going to be a guide to help you learn step by step how to create teams. Warning - This is a tutorial on how to make teams, if you are unsure on how to exactly add player classes, or make them show up while spawning, check the wiki.
Warning - This tutorial is for people with basic scripting knowledge, if you are not scripting savvy, I don't explain the more simple functions. So you should read up the scripter starter guide.
Warning - Expecting to just copy and paste what I have here WILL NOT WORK.
table of contents
1. Setting Up Teams
2. Assigning players to a team.
2.5. Team Colors
3. Team Spawns
4. Saving Teams
5. Team Vehicles
6. Team Bases
7. Extra
1. Teams are very useful in SA:MP. You can make a literal Team, or make them based on Variables. For a team death match for your first game mode, there is a simple SetPlayerTeamFromClass function.
pawn Код:
SetPlayerTeamFromClass(playerid, classid)
pawn Код:
new gTeam[MAX_PLAYERS];
Now to explain what that is in more depth, the gTeam[MAX_PLAYERS]; creates an array for every player in the server, in sa-mp 0.3 that would be 500. Until you set it, it's going to give you a warning, when you compile.
Код:
warning 203: symbol is never used: "gTeam"
If your making a simple team death match then you wont need a lot of this tutorial, but this part is important for later.
Above the main function, you will need to define the teams.
pawn Код:
#define TEAM_GANG 0
#define TEAM_LSPD 1
You do not have to start at the number 0, but it is recommended, as Pawno is a C like language, they can run easier with numbers starting at 0. Since I have never started at the number 1 I cannot say from personal experience if it would give you any problems.
We now have the main components needed to create a two team game.
Now to help people tell the difference from, the gang members and the police members, we will create different skins.
Now the gang team will have a gang member skin. Which we will add first.
pawn Код:
AddPlayerClass(105,-183.5194,1090.8673,19.7422,52.6484,0,0,0,0,0,0); // 0
AddPlayerClass(282,1607.0870,1815.6981,10.8203,193.8336,0,0,0,0,0,0);
Now remember back to when I said Pawno likes counting from zero? Well that is what they do here. I commented the code above to show the corresponding numbers.
I'm sorry but the second line wouldn't comment, and so I removed it.
2. Making a player a part of a team, is a very open subject. If you are scripting an RP server, then you want them to join a Civilian team, if your making a multi team big war game mode, your gonna want them to choose a team before they spawn. ( Same with most Death matches. ) Well for now were gonna be working with Choosing the team before they spawn. If you want to look at how to make an RP type team, move to section 4.
So we now have two player classes, 0 and 1. So now we are going to make the player join a team after he chooses which skin to use.
pawn Код:
public OnPlayerRequestClass(playerid, classid)
pawn Код:
SetPlayerTeamFromClass(playerid, classid);
Under SetPlayerTeamFromClass, put the curly brackets, and a return statement in between.
pawn Код:
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0)
{
gTeam[playerid] = TEAM_GANG;
return 1;
}
else if(classid == 1)
{
gTeam[playerid] = TEAM_LSPD;
return 1;
}
pawn Код:
if(classid == 0)
pawn Код:
gTeam[playerid] = TEAM_GANG;
pawn Код:
else if(classid == 1)
2.5. Setting a color to the team is very easy. The only thing a lot of people have a hard time understanding is that the color you have to use, must be defined earlier in the game mode. EDIT : That is not true, you may use the RGB format instead of the defined color. |
To Define a color in the game mode, it's just like defining a team.
pawn Код:
#define COLOR_GREEN 0x008000FF
#define COLOR_BLUE 0x0000FFFF
Defining a color for use is very helpful, because now instead of typing the RGB format you can just put COLOR_GREEN.
To create a color for a team, you have to use a function called,
SetPlayerToTeamColor
pawn Код:
SetPlayerToTeamColor(playerid)
{
if (gTeam[playerid] == TEAM_GANG)
{
SetPlayerColor(playerid, COLOR_GREEN);
}
else if (gTeam[playerid] == TEAM_LSPD)
{
SetPlayerColor(playerid, COLOR_BLUE);
}
}
For on player spawn if you are making a simple team DM, then you can just make an if statement, else if's to, to choose were they spawn, after they log in and die. If you have interiors on the server always put, SetPlayerInterior(playerid, 0); just in case they die inside an interior.
If your leaning more toward an RP server, you can PM me, and I will help you out with onplayerSpawn.
pawn Код:
public OnPlayerSpawn(playerid)
{
if(gTeam[playerid] == TEAM_GANG)
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, /*Team Spawn Cords*/);
return 1;
}
else if(gTeam[playerid] == TEAM_LSPD)
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, /*Team Spawn Cords*/);
return 1;
}
return 1;
}
4. If your server does not have a saving system don't even bother with this step. I'm not explaining, how to create on, but how to use one. Now if you want players to change teams constantly such as a protect the president or a team DM server then this step is not important. This Step is geared more toward RP servers. What ever save system you have, under register make a new saving component, and make it team, or faction or w/e. On the login command were you can see the stats loading up, add the team one you made above, and make it like this.
pawn Код:
gTeam[playerid] = /* Your Save file for team */
Under OnPlayerDissconnect...
pawn Код:
dini_IntSet(file, team, gTeam[playerid]);
If you came down to this step to hear about RP, teams, I moved it to Extra. ( 7. )
5. Oh yes team vehicles, a very open subject. If you don't want the teams you made to have vehicles that just they can drive, then forget this step.
Personally I found it easier to make an enum, with variables for each faction car I create. You can do it with an Array, but you will have to loop the check. ( You will learn about the check, in a couple lines. )
pawn Код:
enum TeamCars
{
t11
t12
t13
t14
t21
t22
t23
t24
}
new Cars[TeamCars];
Now to create cars to each enum, is the long task.
pawn Код:
Cars[t11] = CreateVehicle(463,-168.0218,1079.2097,19.2757,359.2158,0,0,120);
Under OnPlayerStateChange(playerid, newstate, oldstate) - you have to create a check to see if the car being entered is a team car.
The following code is from my game mode I've been working on.
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == 2)
{
new CarCheck = GetPlayerVehicleID(playerid);
if(CarCheck == Cars[t11] || CarCheck == Cars[t12] || CarCheck == Cars[t13] || CarCheck == Cars[t14] || CarCheck == Cars[t15] || CarCheck == Cars[t16] )
{
if(gTeam[playerid] != 1)
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You Don't have the keys for this car.");
return 1;
}
else
{
return 1;
}
}
return 1;
}
return 1;
}
pawn Код:
if(newstate == 2)
States found here https://sampwiki.blast.hk/wiki/State
If that is correct then it will move onto the next part of the code.
pawn Код:
new CarCheck = GetPlayerVehicleID(playerid);
pawn Код:
if(CarCheck == Cars[t11] || CarCheck == Cars[t12] || CarCheck == Cars[t13] || CarCheck == Cars[t14] || CarCheck == Cars[t15] || CarCheck == Cars[t16] )
pawn Код:
if(gTeam[playerid] != 1)
pawn Код:
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You Don't have the keys for this car.");
Then there is just an Else statement with a return. Which means if they are team one, they can drive the car no problem.
If you have questions on that, post them as a response and I will gladly answer.
6. Team bases, this is really only relevant if you want to make teams have buildings that only they can enter. If you are not interested in that then skip this step. But this step can also help with the IsPlayerInRangeOfPoint function. To keep things nice and simple, I will outline a /enter and /exit command. I'm guessing that you know how to make a command, since the /enter command can be easy it isnt hard to make.
The main portion of the /enter is the if and else if statements that are set up like so.
pawn Код:
if(strcmp(cmd, "/enter", true) == 0)
{
if(IsPlayerInRangeOfPoint(playerid, 2,-179.8969,1087.9668,19.7422))
{
if(gTeam[playerid] == 1)
{
SetPlayerInterior(playerid, 11);
SetPlayerPos(playerid, 501.980987,-69.150199,998.757812);
SendClientMessage(playerid, COLOR_SKYBLUE, "Welcome to the club");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "The door is locked.");
return 1;
}
Explanation -
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 2,-179.8969,1087.9668,19.7422))
If it is true then this will happen.
pawn Код:
if(gTeam[playerid] == 1)
pawn Код:
SetPlayerInterior(playerid, 11);
SetPlayerPos(playerid, 501.980987,-69.150199,998.757812);
SendClientMessage(playerid, COLOR_SKYBLUE, "Welcome to the club");
return 1;
If the team check is found to another team, then this will happen.
pawn Код:
else
{
SendClientMessage(playerid, COLOR_RED, "The door is locked.");
return 1;
}
pawn Код:
else if(IsPlayerInRangeOfPoint(playerid, 2, 501.980987,-69.150199,998.757812))
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, -179.8969,1087.9668,19.7422);
return 1;
If you see I reversed the point to the enter of the first command, and made it place him outside.
7. This is the Extra Section. I will add anything that I find extra, maybe a post someone asked a question, or something I forgot.
RP Teams - Rp Teams are very complex, the game mode will have multiple spawn locations, bases, and commands that differ between team. The best way I can say to have teams is with what ever you like, numbers or defines. Then when a player first register set his team to the Civilian team. That way you can design the /invite, and all the civilian commands around that. The /quitfaction, or /quitteam. It's really up to you, if you really want to learn more about RP teams, post a response and I will reply.