//So let's start with defining our teams, so we can edit them soon easily !
#define TEAM_RED 1
#define TEAM_BLUE 2
//And let's continue with defining our teams' colors
#define TEAM_REDCOLOR 0xFF0000AA // Defines Red Team's color
#define TEAM_BLUECOLOR 0x0000FFAA // Defines Blue Team's color
new gTeam[MAX_PLAYERS];//This is used for checking the player's team
new redcar1; // We will use this soon to track if player's in red team's car or not
new bluecar1; // We will use this soon to track if player's in blue team's car or not
// We will edit this soon aswell to track which team we will put our player at.
AddPlayerClass(106,2522.7515,-1679.2373,15.4970,82.3750,0,0,0,0,0,0); // TEAM_RED's class,spawns at Grove St.
AddPlayerClass(280,1547.0903,-1675.4006,13.9287,90.5706,0,0,0,0,0,0); // TEAM_BLUE's class,spawns at outside of PD.
public OnPlayerRequestClass(playerid, classid)
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerTeamFromClass(playerid, classid); // We will define this function soon for setting the teams for each class.
return 1;
}
public OnPlayerSpawn(playerid)]
public OnPlayerSpawn(playerid)
{
SetPlayerToTeamColour(playerid); // We will define this function soon too for setting the player's color to desired team's color.
return 1;
}
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0) // if the desired class is first class. PAWN and most other programming languages count 0 as first.
{
gTeam[playerid] = TEAM_RED; // Remember, we putted grove street as first, so if the player selects grove street skin, he will spawn as red team member.
}
else if(classid == 1) // else if the desired class is second class. As PAWN counts 0 as first, so 1 is the second skin.
{
gTeam[playerid] = TEAM_BLUE; // Remember, we putted cops as second, so if the player selects the cop skin, he will spawn as blue team member.
}
}
SetPlayerToTeamColour(playerid)
{
if(gTeam[playerid] == TEAM_BLUE) // if the player is a member of blue team
{
SetPlayerColor(playerid,TEAM_BLUECOLOR); // sets the player's color to blue.
}
else if(gTeam[playerid] == TEAM_RED) // if the player is a member of red team
{
SetPlayerColor(playerid,TEAM_REDCOLOR); // sets the player's color to red.
}
}
&& means "and" || means "or"
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 4 || classid == 5) // As PAWN starts counting from 0, 4 is the fifth classid and 5 is the sixth. This means if classid is fifth OR classid is sixth, put them in TEAM BLUE !
{
gTeam[playerid] = TEAM_BLUE;
}
else if(classid == 1)
{
gTeam[playerid] = TEAM_RED;
}
}
new redcar1; // We will use this soon to track if player's in red team's car or not
new bluecar1; // We will use this soon to track if player's in blue team's car or not
public OnGameModeInit()
AddStaticVehicle(560,1534.8514,-1675.0812,13.0939,104.0228,95,83); //
AddStaticVehicle(560,1535.0137,-1697.9331,13.1682,178.7065,95,83); //
redcar1 = AddStaticVehicle(560,1534.8514,-1675.0812,13.0939,104.0228,95,83); // Sets the redcar1 variable to be this vehicle
bluecar1 = AddStaticVehicle(560,1535.0137,-1697.9331,13.1682,178.7065,95,83); // Sets the bluecar1 variable to be this vehicle
public OnPlayerStateChange(playerid, newstate, oldstate)
if(newstate == PLAYER_STATE_DRIVER) // if the player's state is driver, which means if the player has turned his state into driving a car
{
new carid = GetPlayerVehicleID(playerid); // Defines a new variable called "carid" and makes it get the player's vehicle ID.
if(carid == bluecar1)// if the car's ID matches with bluecar1's.
{
if(gTeam[playerid] == TEAM_BLUE) // if player's team is blue.
{
// it won't do something as he matches the car's requirements.
}
else // if player's team is NOT blue
{
SendClientMessage(playerid,TEAM_REDCOLOR,"You must be in Blue Team to drive this car!"); // Sends a message to the player who tried driving the car with red color.
RemovePlayerFromVehicle(playerid);//Removes the player from the vehicle.
}
}
if(carid == redcar1) // if the car's ID matches with redcar1's
{
if(gTeam[playerid] == TEAM_RED) // if player's team is red.
{
// it won't do something as he matches the car's requirements.
}
else // if player's team is NOT red
{
SendClientMessage(playerid,TEAM_REDCOLOR,"You must be in Red Team to drive this car!"); // Sends a message to the player who tried driving the car with red color.
RemovePlayerFromVehicle(playerid);//Removes the player from the vehicle.
}
}
}
#define SetPlayerTeamFromClass(%1,%2) gTeam[%1] = (%2 == 0) ? (TEAM_BLUE) : (TEAM_RED)
#define SetPlayerToTeamColour(%1,%2) SetPlayerColor[%1] = (%2 == 0) ? (TEAM_BLUECOLOR) : (TEAM_REDCOLOR)
forward Yourfunctionhere;
public yourfunctionhere
{
//Therestofyourcode
} //endhere
Please optimize...
pawn Код:
|