SA-MP Forums Archive
team balancer - 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)
+--- Thread: team balancer (/showthread.php?tid=104092)



team balancer - thuron - 22.10.2009

i've been looking around on the forum for a team balancer, or a way to make one. is there a way to get the count of people in a team


Re: team balancer - Peter_Corneile - 22.10.2009

I read the same post 2-3 days before (was it by you ?)


Re: team balancer - thuron - 22.10.2009

nope, i got started with this today, so dont think so


Re: team balancer - Tigerbeast11 - 22.10.2009

I want this too, but I couldn't find anything...


Re: team balancer - Peter_Corneile - 22.10.2009

Quote:
Originally Posted by Tigerbeast11
I want this too, but I couldn't find anything...
So you were the one who asked this before eh ?


Re: team balancer - miokie - 22.10.2009

pawn Код:
new Team1;
new Team2;
new PlayerTeam[playerid];
When a player tries to join team 1:
pawn Код:
if(Team1 < Team 2) //Checks if Team 1 has less players than team 2
{
Team1 += 1; //adds a player to the team
PlayerTeam[playerid] = 1;
return 1; //spawns the player
}
else
{
SendClientMessage(playerid,COLOR,"...");//Message telling the player the team wouldnt be balanced if they joined it.
return 0; // Makes it so the player dosen't spawn.
}
Do the same for team 2.

On Disconnect:
pawn Код:
if(PlayerTeam[playerid] == 1)
{
Team1 -= 1;
}
else
{
Team2 -= 1;
}

UNTESTED. Should work, I think you get the point



Re: team balancer - thuron - 22.10.2009

hmm, i think i already got something, but i also need a function to random set a team. i tryed this, but it wont work:
Код:
new Text:RandomTeamJoin[][] = {
{SetPlayerTeam(playerid,TEAM_BLUE)},
{SetPlayerTeam(playerid,TEAM_RED)}
};
no error, but my pawno gets crazy of it.


Re: team balancer - Tigerbeast11 - 22.10.2009

Quote:
Originally Posted by ►Peter Corneile◄ [hugu-hosting.co.uk
]
Quote:
Originally Posted by Tigerbeast11
I want this too, but I couldn't find anything...
So you were the one who asked this before eh ?
certainly not!


Re: team balancer - thuron - 23.10.2009

ՅՄʍρ


Re: team balancer - Nero_3D - 23.10.2009

pawn Код:
#define NUM_TEAMS (2)
pawn Код:
#if defined NUM_TEAMS
    #if NUM_TEAMS > 1
        new T_Counter[NUM_TEAMS];
    #endif
#endif
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    //other code you got
    #if defined NUM_TEAMS
        #if NUM_TEAMS > 1
            #if !defined gTeam
                #error Team Balancer: didnt found the example team variable, change it!
            #endif
            new bigger_teams;
            for(new i; i < NUM_TEAMS; i++) if(T_Counter[i] > T_Counter[gTeam[playerid]]) bigger_teams++;
            if(bigger_teams < (NUM_TEAMS / 2)) return false;
            T_Counter[gTeam[playerid]]++;
        #endif
    #endif
    //other code you got
}
Examples

1 Team, team balancer is deactivated :O (same when you comment NUM_TEAMS)
2 Teams, players can only join the weakest team
3 Teams, players can only join the weakest team
4 Teams, players can join the two weakest teams
5 Teams, players can join the two weakest teams
6 Teams, players can join the three weakest teams
... and so on ...