09.02.2010, 20:02
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;
}
pawn Код:
new TeamAmounts[AMOUNT_OF_TEAMS];
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]]++;
}
}