[Tutorial] [TUT] Teams - Setting up teams - Team restricted vehicles - Team Restricted base
#1

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)
But before we start all of the setting player team, we need to create variables to tell the script how to check teams. It's a simple variable above the main function.
pawn Код:
new gTeam[MAX_PLAYERS];
That will be our main team Variable. It will be in every team related code.
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"
Don't fret, it is not the end of the world, this is just saying you never used it. This will go away in part 2.
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
The teams are not variables but they define two conditions. Team Gang, and team LSPD. When writing in later you can ignore the numbers they are there to help the compiler.
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);
The first add player is the fat grove street member, the second is a member of the police force.
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)
Look for this in your game mode. Above all the code, put this function.
pawn Код:
SetPlayerTeamFromClass(playerid, classid);
I'm pretty sure that it is self explanatory, but just in case, the function is going to check if the player chose a skin, and set him to a team depending on what we make it check.
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;
}
So I know that might be a lot of code, so lets break it down.

pawn Код:
if(classid == 0)
This is checking to see if the player chose class 0, in our case, the gang member.

pawn Код:
gTeam[playerid] = TEAM_GANG;
This sets the players gTeam Variable to TEAM_GANG, for identification, same thing with the other team.

pawn Код:
else if(classid == 1)
This is an else if statement, it is pretty much saying if the first if statement condition is not met, check this condition. If you want the script to make the second condition a non avoidable thing, make it an else statement. It needs no condition, because it is going to happen.

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
The code next to COLOR_GREEN is the RGB format of the color. You can find a list of them all over with some searching.
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);
    }
}
3. Even with out the complication of teams spawning is a hard topic for some to grasp. Because of that I will explain a little about a player spawning. The OnPlayerSpawn function, is for everytime the player spawns, whether they just logged in, or they died, if you just put, SetPlayerPos(playerid, cords) it will set them all to the same place, All teams alike. While setting the players teams I explained a crappy overview of the if, else if, and else statements. If you really don't understand them, go look at any programing language, they are all the same. Different words same meanings.

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;
}
Just like above the If and the else if statement check the players gTeam, and see if they are in the Gang or LSPD. Then they set there interior to 0, so that they don't spawn in a weird location. And set the position to spawn. And thats it. You can get more in depth, but thats another lesson.

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 OnPlayerDisconnect, you can make the save updating command. I use a dini saving system so here is an example.

Under OnPlayerDissconnect...
pawn Код:
dini_IntSet(file, team, gTeam[playerid]);
That function will take the players gTeam variable and save it on the players file. Then load it back up when they log in.

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];
Each of the things inside the enum is a variable. You call them using Cars[t11] - Using the Variable that has the enum in it's brackets.

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);
If you don't understand what I'm doing there, post a reply with the question, I think it's pretty easy to see. Create a vehicle for every variable in the enum and the vehicles are in the server. Anyone can get in them as of right now, so we need to change that.

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;
}
Time to Explain =D

pawn Код:
if(newstate == 2)
The if statement this time is checking to see if the new state the player entered is the state 2. Which is PLAYER_STATE_DRIVER.
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);
This creates a new variable to get the Vehicle id the player is entering. It will help us identify if the car is one of the ones we made with the enum.

pawn Код:
if(CarCheck == Cars[t11] || CarCheck == Cars[t12] || CarCheck == Cars[t13] || CarCheck == Cars[t14] || CarCheck == Cars[t15] || CarCheck == Cars[t16] )
That If Statement is checking to see if the car entered, using the CarCheck variable, is one of the ones we made for, in my case faction 1.

pawn Код:
if(gTeam[playerid] != 1)
This if statement is checking to see if the gTeam variable for the player entering the vehicle is not team one. != means not equal.

pawn Код:
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You Don't have the keys for this car.");
This is under the if statement checking the team, if the if statement is met, which means the player entering the vehicle is not team 1, they will be removed from the vehicle, and sent a message saying they 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;
            }
This code is for team 1, which happens to be a biker faction.

Explanation -
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 2,-179.8969,1087.9668,19.7422))
This if statement is checking to see if the player is in range of point. In this case the range is 2. ( Range or Sphere is the number after playerid. ) Then the cords to the point.
If it is true then this will happen.

pawn Код:
if(gTeam[playerid] == 1)
This is a quick check to see if the player is part of team 1. If it is true this will happen.

pawn Код:
SetPlayerInterior(playerid, 11);
  SetPlayerPos(playerid, 501.980987,-69.150199,998.757812);
  SendClientMessage(playerid, COLOR_SKYBLUE, "Welcome to the club");
  return 1;
This code will set the players interior to 11, and there position to a certain point. If you are using an interior make sure to set it to the correct interior ID, or you will have people spawning in the air. Then it sends them a message saying "Welcome to the club".

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;
}
Remember that every /enter command must have a mirroring /exit command.

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;
That is the mirror to the first /enter. It is under the /exit command,
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.
Reply
#2

Very nicly explained, only thing i learned from this was setplayerpos under the team thingy... instead of finding cords for each class.. just all in 1.. thx.
Reply
#3

Quote:
Originally Posted by otaybay
Very nicly explained, only thing i learned from this was setplayerpos under the team thingy... instead of finding cords for each class.. just all in 1.. thx.
Thanks glad you learned something
Reply
#4

the numbers in the defines aren't just "to help the compiler." The pre-processer essentially does a Ctrl+h
replace: TEAM_GANG
with : 0

and I would recommend putting the number in braces () so it would be

replace: TEAM_LSPD
with : (1)

UNLESS you plan on doing something like this, which i am not even sure works, and looks pretty sloppy.

[pawn]
#define TEAM_GOOD 1
#define _LSPD 1
#define _LSFD 2

#define TEAM_BAD 2
#define _ROBBERS 1
#define _WHITE_HOUSE 2
[pawn]

you could then do something (again not sure on this) like this:
pawn Код:
if (teamid == TEAM_GOOD_LSPD)
that would be teamid 11.
Reply
#5

Nice and Basic Instructions.
Good Tutorial. 7/10.
Reply
#6

Quote:
Originally Posted by Daren_Jacobson
the numbers in the defines aren't just "to help the compiler." The pre-processer essentially does a Ctrl+h
replace: TEAM_GANG
with : 0

and I would recommend putting the number in braces () so it would be

replace: TEAM_LSPD
with : (1)

UNLESS you plan on doing something like this, which i am not even sure works, and looks pretty sloppy.

[pawn]
#define TEAM_GOOD 1
#define _LSPD 1
#define _LSFD 2

#define TEAM_BAD 2
#define _ROBBERS 1
#define _WHITE_HOUSE 2
[pawn]

you could then do something (again not sure on this) like this:
pawn Код:
if (teamid == TEAM_GOOD_LSPD)
that would be teamid 11.
this is more for beginners who just want to make some teams. Thats getting a little to complex when you can keep it simple. Plus you unless your going to be doing some heavy team based scripting, this is enough. Then again if your doing heavy team based scripting you wont even need this.
Reply
#7

ignore everything except the top line of that post, that is just what happens when i start thinking about stuff, the point i meant to get across is the first line.
Reply
#8

Why would you need array gTeams since you can use GetPlayerTeam? That array was needed in previous versions where GetPlayerTeam didn't work, but now it's completly useless since that native works.
Reply
#9

Quote:
Originally Posted by $ЂЯĢ
Why would you need array gTeams since you can use GetPlayerTeam? That array was needed in previous versions where GetPlayerTeam didn't work, but now it's completly useless since that native works.
I havnt gotten around to using it. I'll see what I could do with it, and change this around if I find it easier.
Reply
#10

Nice tutorial, much better than your last one
8/10 (Y)
Reply
#11

Quote:
Originally Posted by lrZ^ aka LarzI
Nice tutorial, much better than your last one
8/10 (Y)
I never made a last tutorial This one is my first. Thanks though =)
Reply
#12

could you please post for Rp teams?
Reply
#13

Quote:
Originally Posted by Ritchie999
could you please post for Rp teams?
What do you mean RP teams?

Good job.

Should be added in Wiki. But
Quote:
Originally Posted by SA-MP_Wikipedia
Note: new user registration for page editing on this wiki is currently disabled due to spamming
Rated :
★★★★★/☆☆☆☆☆
Reply
#14

Quote:
Originally Posted by www.******.com|*I pastebin*|
Quote:
Originally Posted by Ritchie999
could you please post for Rp teams?
What do you mean RP teams?

Good job.

Should be added in Wiki. But
Quote:
Originally Posted by SA-MP_Wikipedia
Note: new user registration for page editing on this wiki is currently disabled due to spamming
Rated :
★★★★★/☆☆☆☆☆
Sorry i made it a bit confusing.. what i mean is RolePlay factions, like police, swat, ballas, grove street
Reply
#15

Quote:
Originally Posted by retart441
Quote:
Originally Posted by lrZ^ aka LarzI
Nice tutorial, much better than your last one
8/10 (Y)
I never made a last tutorial This one is my first. Thanks though =)
me = failer
My bad x)
I switched you with another member , sorry
Reply
#16

very nice, just having a tiny issue with it, just been futzing around with it and i seam to have broke something xD


its a warning but ya...

pawn Code:
warning 203: symbol is never used: "SetPlayerTeamFromClass"


SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 0)
    {
        gTeam[playerid] = TEAM_ARMY;
    return 1;
  }
    else if(classid == 1)
  {
    gTeam[playerid] = TEAM_REBAL;
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
  if(classid == 0)
  {
    SendClientMessage(playerid, COLOR_GREEN, "ARMY!");
  }
  else if(classid == 1)
  {
    SendClientMessage(playerid, COLOR_BLUE, "REBAL!");
  }
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}
Reply
#17

What do you want to learn with Roleplay style teams?
Reply
#18

Quote:
Originally Posted by retart441
What do you want to learn with Roleplay style teams?
i need it so you dont pick the team, either you spawn off and your instantly in the gang team like grove street or else you go to the police station if your a cop and go on duty
Reply
#19

This is very nice .. Well done retart441
Reply
#20

Quote:
Originally Posted by [LCG
TANKER ]
very nice, just having a tiny issue with it, just been futzing around with it and i seam to have broke something xD


its a warning but ya...

pawn Code:
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerTeamFromClass(playerid, classid)
    {
    if(classid == 0)
    {
    gTeam[playerid] = TEAM_ARMY;
    return 1;
    }
    else if(classid == 1)
    {
    gTeam[playerid] = TEAM_REBAL;
    return 1;
    }

    public OnPlayerRequestClass(playerid, classid)
    {
    if(classid == 0)
    {
    SendClientMessage(playerid, COLOR_GREEN, "ARMY!");
    }
    else if(classid == 1)
    {
    SendClientMessage(playerid, COLOR_BLUE, "REBAL!");
    }
    return 1;
}
Try that. Sorry for the indentation errors.

And to make people spawn as a cop or a gang member, you want them to choose a skin or it to be random??

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)