SA-MP Forums Archive
[UnSolved] Team balancing? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [UnSolved] Team balancing? (/showthread.php?tid=126709)



[UnSolved] Team balancing? - bajskorv123 - 09.02.2010

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.



Re: [UnSolved] Team balancing? - Torran - 09.02.2010

What do you mean by Team Balancing


Re: [UnSolved] Team balancing? - [XAC]Klinsen - 09.02.2010

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)


Re: [UnSolved] Team balancing? - Ironboy500 - 09.02.2010

Search.


Re: [UnSolved] Team balancing? - Joe Staff - 09.02.2010

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]]++;
  }
}