Team Balancer
#1

Heey guys!

Can someone help me with making a team balancer for my server?

My two teams:

PHP код:
#define TERRORISTS 0
#define SWAT 1 
variable:

PHP код:
new gTeam[MAX_PLAYERS]; 
Please help me,

Thanks
Reply
#2

You'll have to be a bit more specific. What do you define by team balancing?
  • Equal amount of players on each team
  • Skill based (for example: kill death ratio)
  • Custom conditions
  • ...
When should the team balancing happen?
  • Every few minutes
  • When one team gets too big of an advantage
  • Custom conditions
  • ...
Reply
#3

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
You'll have to be a bit more specific. What do you define by team balancing?
  • Equal amount of players on each team
  • Skill based (for example: kill death ratio)
  • Custom conditions
  • ...
When should the team balancing happen?
  • Every few minutes
  • When one team gets too big of an advantage
  • Custom conditions
  • ...
I want that the equel amount on players and when a player requests the spawn for a team
Reply
#4

Use OnPlayerRequestSpawn
check if the team has more players than the other, return the error and 'return 0;'

use a global timer to adjust teams, if you want to keep it like Counter-Strike or other Source engine based games.
Reply
#5

Quote:
Originally Posted by Fantje
Посмотреть сообщение
I want that the equel amount on players and when a player requests the spawn for a team
Ok, so as ALiScripter mentioned, you will have to use OnPlayerRequestSpawn. Or you alternatively you can use the shorter OnPlayerRequestClass method.

Method 1: OnPlayerRequestSpawn
Код:
//Globals
new requestedTeam[MAX_PLAYERS];

//OnPlayerRequestClass
requestedTeam[playerid] = classid;

//OnPlayerRequestSpawn
new teamTerroristsPlayers, teamSwatPlayers;
for(new otherplayerid = 0, playerCount = GetPlayerPoolSize(); otherplayerid <= playerCount; otherplayerid++) {
    if(gTeam[otherplayerid] == TERRORISTS) {
        teamTerroristsPlayers++;
    } else {
        teamSwatPlayers++;
    }
}
//If there are less terrorists than swat players and the player chose the swat class
//OR if there are less swat than terrorists players and the player chose the terrorists class
if((teamTerroristsPlayers < teamSwatPlayers && requestedTeam[playerid] == USE_SWAT_CLASS_HERE)
|| (teamSwatPlayers < teamTerroristsPlayers && requestedTeam[playerid] == USE_TERRORISTS_CLASS_HERE)) {
    return 0; //Don't let the player spawn
} 
//If there are less terrorists than swat players and the player chose the terrorists class
//OR if there are less swat than terrorists players and the player chose the swat class
//OR if the amount of terrorists players is equal to the amount of swat players, regardless of the chosen class
else {
    if(requestedTeam[playerid] == USE_TERRORISTS_CLASS_HERE) {
        gTeam[playerid] = TERRORISTS;
    } else {
        gTeam[playerid] = SWAT;
    }
    return 1; //Let the player spawn
}
Method 2: OnPlayerRequestClass
Код:
//OnPlayerRequestClass
new teamTerroristsPlayers, teamSwatPlayers;
for(new otherplayerid = 0, playerCount = GetPlayerPoolSize(); otherplayerid <= playerCount; otherplayerid++) {
    if(gTeam[otherplayerid] == TERRORISTS) {
        teamTerroristsPlayers++;
    } else {
        teamSwatPlayers++;
    }
}
if((teamTerroristsPlayers < teamSwatPlayers && classid == USE_SWAT_CLASS_HERE)
|| (teamSwatPlayers < teamTerroristsPlayers && classid == USE_TERRORISTS_CLASS_HERE)) {
    return 0;
} else {
    if(classid == USE_TERRORISTS_CLASS_HERE) {
        gTeam[playerid] = TERRORISTS;
    } else {
        gTeam[playerid] = SWAT;
    }
    return 1;
}
Reply
#6

Can someone help me inplementing this into my script please. Please pm me your skype.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)