Looking For TeamBalancer [URGENT]
#1

Right...Before you ask i have tried serching for it and i found one but its for 2 teams so i tried to make it into 7 teams but failed.

If anyone could make me a TeamBalancer that balances 7 teams ingame i will reward them with some money.

Thanks Alot - Kyle

(P.S This balancer is for a Protect The President GameMode)
Reply
#2

Hmm, 7 teams is a bit more tricky. I suppose you can just add new players to the team with the least amout of players, keeping an eighth variable that keeps track of what team is the smallest.
Reply
#3

I just learned this some time ago, it's called 'module division', I've got a big problem with maths so I can't really explain it to you good, but I give you an example which I use myself:


pawn Код:
// on top
new PlayerTeam[MAX_PLAYERS];
new team;

// somewhere else:

for (new i = 0; i <MAX_PLAYERS; i ++)
{
  if(IsPlayerConnected(i))
  {
    team = playerid % 2;

    if(team == 0)
    {
      PlayerTeam[i] = 1;
    }
    if(team == 1)
    {
      PlayerTeam[i] = 2;
    }
  }
  return 1;
}
This would (if you had 50 players), make 25 people team 1 and the other 25 people team 2, if a new player would connect, you could do (make sure to set PlayerTeam[playerid] to 0 at (dis)connect) onplayerspawn:

pawn Код:
if(PlayerTeam[playerid] == 0)
{
  team = playerid % 2;
  if(team == 0)
  {
    PlayerTeam[i] = 1;
  }
  if(team == 1)
  {
    PlayerTeam[i] = 2;
  }
}
No idea how to do it for 7 teams lol I'm too noob for that, but take a look at the wiki page, might make more sense to you then me:

http://en.wikipedia.org/wiki/Modulo_operation
Reply
#4

..Confusing
Reply
#5

7 teams? I'll try to solve it.
I'm presuming you're changing pTeam in OnPlayerRequestClass and checking it in OnPlayerRequestSpawn
Let's go
pawn Код:
public OnPlayerRequestSpawn(playerid){
  for(new i;i < 7;i++){//loop 7 team
    if(gTeam_Amount[gTeam[i]] < gTeam_Amount[gTeam[playerid]]){// find a team is smaller than player team
      sendfmsg(playerid,COLOR_SYSTEM,"Team %s(%i) has too much ppl, try to select other teams(Team %s(%i) needs the man).", gTeam_name[gTeam[playerid]],gTeam[playerid],gTeam_name[gTeam[i]],gTeam[i]);
      return false;
    }
    sendfmsg(playerid,gTeam_color[gTeam[playerid]],"You join team %s(%d)",gTeam_name[gTeam[playerid]],gTeam[playerid]);
    return true;
}
Bere's the simulation
Код:
0 0 0 0
1 0 0 0
1 0 0 1
1 0 1 1
1 1 1 1
1 1 1 2
2 1 1 2
2 2 1 2
2 2 2 2
.
.
.
The most injustice condition is
Код:
8 8 8 8 8 8 7
Edit:I did something wrong, now fix it
Reply
#6

Woulden't it be better if you evened out the team numbers. Like 8 teams? Woulden't that make it a little easyer to do?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)