PDA

View Full Version : team balancer


thuron
22/10/2009, 06:44 PM
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???

Peter_Corneile
22/10/2009, 07:28 PM
I read the same post 2-3 days before (was it by you ?)

thuron
22/10/2009, 07:42 PM
nope, i got started with this today, so dont think so ;)

Tigerbeast11
22/10/2009, 07:43 PM
I want this too, but I couldn't find anything... :(

Peter_Corneile
22/10/2009, 07:45 PM
I want this too, but I couldn't find anything... :(

So you were the one who asked this before eh ?

miokie
22/10/2009, 07:45 PM
new Team1;
new Team2;
new PlayerTeam[playerid];

When a player tries to join team 1:

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:

if(PlayerTeam[playerid] == 1)
{
Team1 -= 1;
}
else
{
Team2 -= 1;
}



UNTESTED. Should work, I think you get the point ;)

thuron
22/10/2009, 07:47 PM
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.

Tigerbeast11
22/10/2009, 07:49 PM
]

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

So you were the one who asked this before eh ?


certainly not!

thuron
23/10/2009, 03:53 PM
ՅՄʍρ

Nero_3D
23/10/2009, 04:32 PM
#define NUM_TEAMS (2)
#if defined NUM_TEAMS
#if NUM_TEAMS > 1
new T_Counter[NUM_TEAMS];
#endif
#endif
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 ...

thuron
23/10/2009, 05:50 PM
you dont get it. it is just that it works, but i want to get 1 more function working. that is a random team choose. i almost have it, i just need this fixed:

new Text:RandomTeamJoin[2][2] = {
{SetPlayerTeam(playerid,TEAM_BLUE)},
{SetPlayerTeam(playerid,TEAM_RED)}
};

Nero_3D
23/10/2009, 06:00 PM
if you just want a random team, do something like

SetPlayerTeam(playerid, random(DIFFERENT_TEAMS));

also if you got two teams then it would be

SetPlayerTeam(playerid, random(2));

but that only works if you defined your team with the right numbers or with enum

if you do it with an array

new RandomTeamJoin[2] = { TEAM_BLUE, TEAM_RED };
SetPlayerTeam(playerid, RandomTeamJoin[random(sizeof(RandomTeamJoin))]);

if I still didnt understand it correctly, please explain what you wanted to do with


new Text:RandomTeamJoin[2][2] = {
{SetPlayerTeam(playerid,TEAM_BLUE)},
{SetPlayerTeam(playerid,TEAM_RED)}
};

thuron
23/10/2009, 06:04 PM
thanks man, this worked:

new RandomTeamJoin[2] = { TEAM_BLUE, TEAM_RED };


SetPlayerTeam(playerid, RandomTeamJoin[random(sizeof(RandomTeamJoin))]);

no errors or other crap, so gonna test it, when i did that, ill tell if it worked in-game too.

thuron
23/10/2009, 06:44 PM
with that, it will always choose team blue when there is a even count of players in both teams...

Nero_3D
23/10/2009, 07:01 PM
with that, it will always choose team blue when there is a even count of players in both teams...


thats not true...


#define TEAM_BLUE 1
#define TEAM_RED 2

new RandomTeamJoin[2] = { TEAM_BLUE, TEAM_RED };

for(new i; i < 100; i++)
printf("%d", RandomTeamJoin[random(sizeof(RandomTeamJoin))]);

[20:59:27] 2
[20:59:27] 1
[20:59:27] 2
[20:59:27] 2
[20:59:27] 1
[20:59:27] 1
[20:59:27] 1
[20:59:27] 1
[20:59:27] 1
[20:59:27] 1


... you just got unluck

thuron
23/10/2009, 07:14 PM
ah, indeed, i had to get out a few lines for a while ... but it worked. ty

mini_mi
30/08/2012, 03:53 PM
guys i need team balancer file script if u can make it drop me a pm plz plz