06.12.2012, 05:02
(
Last edited by Jarnu; 15/01/2013 at 07:16 AM.
Reason: Updated.
)
Starting.
Extra note -
__________________________________________________ ___________
Well, for the sake of tutorial i'll define 3 teams.
Team variable
OnPlayerRequestClass
-You've to do it according to your script.
We will use the above definations in tutorial.
Remeber: If you already got team defines ignore this step.
__________________________________________________ ___________
Step1: Creating the function to check the player's count in a team.
We will create a simple stock/function that will get the player's count in a particular team.
Extra: I used stock rather than public because with stock you can return a string, but a public function can't
Step2: Implementing the function we created.
Now, we will use the above function for restricting the player to join a team which has more player's than the other teams.
For that restriction we will use the call back OnPlayerRequestSpawn
And with a 1 simple function we created a team balancer!
Thank you for reading the tutorial.
Extra note -
__________________________________________________ ___________
Well, for the sake of tutorial i'll define 3 teams.
pawn Code:
#define TEAM1 0
#define TEAM2 1
#define TEAM3 2
pawn Code:
new gTeam[MAX_PLAYERS];
-You've to do it according to your script.
pawn Code:
public OnPlayerRequestClass(playerid, classid)
{
switch(classid)
{
case 0: { gTeam[playerid] = TEAM1; SetPlayerTeam(playerid, 0); }
case 1: { gTeam[playerid] = TEAM2; SetPlayerTeam(playerid, 1); }
case 2: { gTeam[playerid] = TEAM3; SetPlayerTeam(playerid, 2); }
}
return 1;
}
//REMEMBER: YOU HAVE TO USE IT ACCORDING TO YOUR SCRIPT THIS IS JUST AN EXAMPLE.
Remeber: If you already got team defines ignore this step.
__________________________________________________ ___________
Step1: Creating the function to check the player's count in a team.
We will create a simple stock/function that will get the player's count in a particular team.
pawn Code:
//Remeber you must have already defined teams.
stock GetPlayersCountInTeam(teamid) //This is our function "GetPlayersCountInTeam(teamid)"
{
//We will create a variable here called "playercount" or you can define it as your own like "count" or something else you want.
new playercount = 0; //We set it to '0' since we didn't counted any players yet.
//Next is a 'for loop'.
for(new x = 0; x < MAX_PLAYERS; x ++)
{
if(GetPlayerState(x) == PLAYER_STATE_NONE) continue; //If player is in class selection, continue.
if(GetPlayerTeam(x) != teamid) continue; //If the player is not a specified team id. then continue;
playercount++; //Else count the player in the team. (The team you will use in GetPlayersCountInTeam function)
}
return playercount; //Will return the players count in that team.
}
Step2: Implementing the function we created.
Now, we will use the above function for restricting the player to join a team which has more player's than the other teams.
For that restriction we will use the call back OnPlayerRequestSpawn
pawn Code:
public OnPlayerRequestSpawn(playerid) //When the player clicks the SPAWN button
{
new team1count = GetPlayersCountInTeam(TEAM1); //Team 1 count's variable
new team2count = GetPlayersCountInTeam(TEAM2); //Team 2 count's variable
new team3count = GetPlayersCountInTeam(TEAM3); //Team 3 count's variable
switch(gTeam[playerid]) //We will use the switch case.
{
case TEAM1: //If player's team is TEAM1
{
if(team1count > team2count && team3count) //if the player's count of TEAM1 is > (greater) than the team 2's count and team 3's count then.
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0; //Stopping the player to Spawn
}
}
case TEAM2: //If player's team is TEAM2
{
if(team2count > team1count && team3count) //if the player's count of TEAM2 is > (greater) than the team 1's count and team 3's count then.
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0; //Stopping the player to Spawn
}
}
case TEAM3: //If player's team is TEAM3
{
if(team3count > team1count && team2count) //if the player's count of TEAM3 is > (greater) than the team 1's count and team 2's count then.
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0; //Stopping the player to Spawn
}
}
}
return 1; //Else spawn the player.
} //Ending bracket.
And with a 1 simple function we created a team balancer!
Thank you for reading the tutorial.