31.07.2011, 02:24
(
Последний раз редактировалось CyNiC; 15.09.2011 в 20:35.
)
This function balance the server teams distributing all players on how many teams you put in the brackets.
Just tested with variables manipulation.
Just tested with variables manipulation.
pawn Код:
stock BalanceTeams(...)
{
new PlayersIds[MAX_PLAYERS] = {-1, ...}, highid, Args = numargs(), divisor;
for(new i, slot, j = GetMaxPlayers(); i < j; i++)
{
if(IsPlayerConnected(i) && !IsPlayerNPC(i) && GetPlayerState(i))
{
do
{
if(PlayersIds[slot] == -1)
{
PlayersIds[slot] = i;
break;
}
slot++;
}
while(slot < sizeof PlayersIds);
highid++;
}
}
divisor = (highid / Args);
if(highid <= 1 || Args <= 1) return false;
if(Args > highid) Args = highid;
for(new i = 0, Arg = 0; i < highid; i++)
{
if(i == (highid - 1) && (highid % Args))
{
SetPlayerTeamEx(PlayersIds[i], getarg(random(Args)));//Put the remaining in a random team
return true;
}
SetPlayerTeamEx(PlayersIds[i], getarg(Arg));
if((i == (((divisor * Arg) + divisor) - 1) && i) || (i == ((divisor * 1) - 1)) ) Arg++;
}
return true;
}