Team Balance
#1

~fixed~
Reply
#2

maybe this example help you.

pawn Code:
new team1 = 6;  // exm team 1 has 6 players
new team2 = 10;  // exm team 2 heas 10 players
new timer;



public OnFilterScriptInit()
{
    timer = SetTimer("balanceteams", 1000, 1);
    return 1;
}



public OnFilterScriptExit()
{
    return 1;
}


public balanceteams()
{
    if (team1 > team2)
    {
        team2++;
        team1--;
    }
    if (team1 < team2)
    {
        team2--;
        team1++;
    }
    if(team1 == team2)
    {
        KillTimer(timer);
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Anak
View Post
maybe this example help you.

pawn Code:
new team1 = 6;  // exm team 1 has 6 players
new team2 = 10;  // exm team 2 heas 10 players
new timer;



public OnFilterScriptInit()
{
    timer = SetTimer("balanceteams", 1000, 1);
    return 1;
}



public OnFilterScriptExit()
{
    return 1;
}


public balanceteams()
{
    if (team1 > team2)
    {
        team2++;
        team1--;
    }
    if (team1 < team2)
    {
        team2--;
        team1++;
    }
    if(team1 == team2)
    {
        KillTimer(timer);
    }
    return 1;
}
What are you thinking? That isn't a solution at all.


Start up
---------------------------------
1) Get a list of all active players
2) Randomize list
3) Divide active player count by 2
4) Join players on both teams

--------------------------------

Removing / Joining players
--------------------------------
Player joins game
1) Find which team has lowest player count
2) Join player to team with lowest count if equal choose a random team

Please leaves game (disconnects, /exitround etc...) (This will be your update timer)
1) Update player team count (Textdraws)
2) If player team count is different than the last update do steps 3, and 4
3) Find which team has lowest player count
4) If the count is greater than 1 swap a player from higher team
Reply
#4

Try that
pawn Code:
stock Balance() {
    new
        count,
        player[MAX_PLAYERS]
    ;
    foreach(Player, i) {
        player[count++] = i;
    }
    for(new rand, half = count / 2; halft--; count--) {
        rand = random(count);
        HumanSetup(player[rand]);
        player[rand] = player[count];
    }
    while(count) {
        ZombieSetup(player[--count]);
    }
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)