Creating teams
Setting up teams
Teams is one of the most common things in sa-mp and here is how to do it,
// Define the teams so its easier to use later
#define TEAM_BLUE 1
#define TEAM_GREEN 2
// Define the colours you want each team to be, its easier for later on
#define TEAM_BLUE_COLOUR 0x0000BBAA // blue duh
#define TEAM_GREEN_COLOUR 0x33AA33AA // green duh
// Tracks what team a player is in
new gTeam[MAX_PLAYERS];
Copy that in to a blank script above main()
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); // blue team
AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); // green team
Add them 2 as classes under ongamemodeinit
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerTeamFromClass(playerid, classid); // calls the custom function
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerToTeamColour(playerid); // calls the custom function
return 1;
}
Make your callbacks look like that
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0)
{
gTeam[playerid] = TEAM_BLUE; // using the defines at the top
}
else if(classid == 1)
{
gTeam[playerid] = TEAM_GREEN; // same ^^
}
}
SetPlayerToTeamColour(playerid)
{
if(gTeam[playerid] == TEAM_BLUE)
{
SetPlayerColor(playerid,TEAM_BLUE_COLOUR); // Blue
}
else if(gTeam[playerid] == TEAM_GREEN)
{
SetPlayerColor(playerid,TEAM_GREEN_COLOUR); // Green
}
}
Put that at the bottom of your script and your good to go! try it out and then experiment, add more teams in that way.
Here is my whole script
#include <a_samp>
// Define the teams so its easier to use later
#define TEAM_BLUE 1
#define TEAM_GREEN 2
// Define the colours you want each team to be, its easier for later on
#define TEAM_BLUE_COLOUR 0x0000BBAA // blue duh
#define TEAM_GREEN_COLOUR 0x33AA33AA // green duh
// Tracks what team a player is in
new gTeam[MAX_PLAYERS];
main()
{
print("\n----------------------------------");
print(" Teams");
print("----------------------------------\n");
}
public OnGameModeInit()
{
SetGameModeText("Teams");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); // blue team
AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); // green team
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerTeamFromClass(playerid, classid); // calls the custom function
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerToTeamColour(playerid); // calls the custom function
return 1;
}
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0)
{
gTeam[playerid] = TEAM_BLUE; // using the defines at the top
}
else if(classid == 1)
{
gTeam[playerid] = TEAM_GREEN; // same ^^
}
}
SetPlayerToTeamColour(playerid)
{
if(gTeam[playerid] == TEAM_BLUE)
{
SetPlayerColor(playerid,TEAM_BLUE_COLOUR); // Blue
}
else if(gTeam[playerid] == TEAM_GREEN)
{
SetPlayerColor(playerid,TEAM_GREEN_COLOUR); // Green
}
}
Sorry for the very breif explanation, i might add a better one sometime.