[UnSolved] Team balancing?
#1

Hey, I need team balancing for my server, I'm using gTeam and have 2 teams.
And please dont say what i should do, because i need codes, that are as clear as possible, Thanks.
Reply
#2

What do you mean by Team Balancing
Reply
#3

i.e. Team 1 has 15 users and Team 2 only 5. If you balance the teams both will have 10 users. ((team1+team2) / 2)
Reply
#4

Search.
Reply
#5

pawn Код:
stock FindSmallestCell(array[],len=sizeof(array))
{
  new _smallest,_value=0x7FFFFFFE; //_value = Largest Possible Value
  for(new cell;cell<len;cell++)
  {
    if(array[cell]<_value)
    {
      _smallest=cell;
      _value=array[cell];
    }
  }
  return _smallest;
}
You would use this with a variable like
pawn Код:
new TeamAmounts[AMOUNT_OF_TEAMS];
Which you would add to everytime a player joins a particular team so if you wanted to find the team for a player you'd try this
pawn Код:
pTeam[playerid]=FindSmallestCell(TeamAmounts,AMOUNT_OF_TEAMS); //Find the team for the player and set that player to that team
TeamAmounts[pTeam[playerid]]++; //Add to that teams 'TeamAmount'


This could also be used to re-balance the teams

pawn Код:
RebalanceTeams()
{
  for(new team;team<AMOUNT_OF_TEAMS;team++)TeamAmounts[team]=0;
  for(new playerid;playerid<MAX_PLAYERS;playerid++)
  {
    if(!IsPlayerConnected(playerid))continue;
    pTeam[playerid]=FindSmallestCell(TeamAmounts,AMOUNT_OF_TEAMS);
    TeamAmounts[pTeam[playerid]]++;
  }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)