How to make team balancer?
#1

How to make a team balancer?
Its so non-fair because green team is empty, red team is full.
Reply
#2

Create a variable for each time, like Team1 and Team2

Код:
new Team1;
new Team2;
And every time you assign a player to a team add 1 to the variable and every time you remove a player from a team, subtract 1 from that specific team

And from there make sure there is in imbalance, so if you only want to let the teams have 2 more players than each other before auto balance commences then do something like


Код:
new check = Team1 + 2;
If(check > Team2) {
// Autobalance
} 
check = Team2 + 2;
else if(check > Team1) {
// Autobalance
}
Hope it works
Bottom line is you need to run checks to compare them as a ratio.
_____
Anyway if you havent searched there are tutorials out.

Код:
#include <a_samp>//If i need to explain this to you, may god have mercy on your soul..
//-----------------------------------[STEP 1]---------------------------------//
//Ok, Im going to use two teams for this tutorial, TEAM_ONE & TEAM_TWO,
//you could simply add more later. Type the following below:
#define TEAM_ONE 0
#define TEAM_TWO 1
//-----------------------------------[STEP 2]---------------------------------//
//Ok, now we have defined our teams(classes) we need to make a variable
//that checks the players team, so we can use a function(shown below)
//later to check there team, type the following below:
static gTeam[MAX_PLAYERS];//Yes its very common..
//Now we can use gTeam[playerid] == TEAM_ONE or gTeam[playerid] == TEAM_TWO..
//-----------------------------------[STEP 2]---------------------------------//
//Now, we need to create a stock which loops through MAX_PLAYERS, counting
//how many online players are in our specified team, returning a player count
//as an integra(number), This stock was developed by myself so keep my credits!
//i will show you below how it works:
stock GetPlayersInTeamFromMaxPlayers(teamid)//Stock developed by Weponz (Weponz Inc. © 2010 - 2011)
{
    new playercount = 0;//Set our count to 0 as we have not counted any players yet..
    for(new i = 0; i < MAX_PLAYERS; i++)//Loop through MAX_PLAYERS(I suggest you redefine MAX_PLAYERS to ensure max efficency)..
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;//If a player is in class selection continue..
        if(gTeam[i] != teamid) continue;//If a player is NOT in the specified teamid continue..
        playercount++;//else (there in the teamid) so count the player in the team..
    }
    return playercount;//Return the total players counted in the specified team..
}
//-----------------------------------[STEP 3]---------------------------------//
//Ok, now we can count how many players are in w/e team we check
//with our new function GetPlayersInTeamFromMaxPlayers(teamid) we can now
//check for team in-balance under OnPlayerRequestSpawn as its most efficent..
public OnPlayerRequestSpawn(playerid)
{
    new team1 = GetPlayersInTeamFromMaxPlayers(TEAM_ONE);//team1 = how many players are in TEAM_ONE..
    new team2 = GetPlayersInTeamFromMaxPlayers(TEAM_TWO);//team2 = how many players are in TEAM_TWO..
    if(team1 > team2 && gTeam[playerid] == TEAM_ONE)//if team1 has more players than team2 and the player is trying to spawn as TEAM_ONE..
    {
        GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Another Team!", 3000, 5);//Tell them its full, choose another team..
        return 0;//And stop them from spawning..
    }
    else if(team2 > team1 && gTeam[playerid] == TEAM_TWO)//if team2 has more players than team1 and the player is trying to spawn as TEAM_TWO..
    {
        GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Another Team!", 3000, 5);//Tell them its full, choose another team..
        return 0;//And stop them from spawning..
    }
    return 1;
}
Reply
#3

Thank you RanSee it work, and thank you ****** for trying to help.
Both rep for you guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)