12.06.2014, 21:22
Hello guys,
Here I come with just another tutorial ! Today, we will make a basic team script with team restricted vehicles. I don't want to talk too much. So let's start !
First of all, we need our defines and variables !
So we are done with top of our script, but is it ended ? Of course not !
Now let's add player classes for each team, shall we ?
Now search for this in your gamemode:
We will edit here to set the spawned player's team to a specific team. So let's go:
So we implemented one custom function to our script and will have to define it soon. Is it a problem ? Of course not ! However, we will also have to set player's color to his team's color. First of all you will have to search for this in your gamemode:
We will edit here to set the spawned player's color to a desired team's color. So let's go:
So we are done with everything to set a team up, but we have got 2 undefined functions and we must define them. So let's go ! :
You can add as more classes as you wish to, but as this is basic team script 2 will be enough for us. However, if you want to add more than one, you will have to know these mathematical operations:
For example, I want fifth classid and sixth classid to be in TEAM_BLUE, the correct code would be
You can edit this team script for your needs. Now let's go for team restricted vehicles !
remember we defined our team cars with
Now it is time to use them. Search for
in your pawno and create a vehicle, for me vehicles will be these:
Both of them are sultans which spawn in front of the PD station in LS. Now we will have to define these cars as our team cars.
So we are done with setting our team cars, now it is time for making them restricted ! For this, search for this in your pawno:
We will edit here to get the player's state and check if he enters our redcar1 or bluecar1, so lets start:
Add this:
So, that is all guys ! I appreciate any feedbacks ^^
Have fun !
Here I come with just another tutorial ! Today, we will make a basic team script with team restricted vehicles. I don't want to talk too much. So let's start !
First of all, we need our defines and variables !
pawn Код:
//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
Now let's add player classes for each team, shall we ?
pawn Код:
// 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.
pawn Код:
public OnPlayerRequestClass(playerid, classid)
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerTeamFromClass(playerid, classid); // We will define this function soon for setting the teams for each class.
return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)]
pawn Код:
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;
}
pawn Код:
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"
pawn Код:
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;
}
}
remember we defined our team cars with
pawn Код:
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
pawn Код:
public OnGameModeInit()
pawn Код:
AddStaticVehicle(560,1534.8514,-1675.0812,13.0939,104.0228,95,83); //
AddStaticVehicle(560,1535.0137,-1697.9331,13.1682,178.7065,95,83); //
pawn Код:
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
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
Add this:
pawn Код:
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.
}
}
}
Have fun !