TeamBalancer Help
#1

Well for a few days now, ive been failing with the team balancer. it doesnt work well. USA team is always full, when its not.. and players are allowed to join teams with 10 players while others have 2 and 3 players

help!

Код:
new count[4];
for(new p = 0; p < GetMaxPlayers(); p++)
{
	if (gTeam[p] == TEAM_USA) count[0]++;
	else if (gTeam[p] == TEAM_CHINA) count[1]++;
	else if (gTeam[p] == TEAM_IRAN) count[2]++;
  else if (gTeam[p] == TEAM_RUSSIA) count[3]++;
}
switch(gTeam[playerid])
{
case TEAM_USA: if(count[0] > count[1] && count[0] > count[2] && count[0] > count[3]) return SendClientMessage(playerid, COLOR_RED, ">>>>>>>This team is full!"), 0;
case TEAM_CHINA: if(count[1] > count[0] && count[1] > count[2] && count[1] > count[3]) return SendClientMessage(playerid, COLOR_RED, ">>>>>This team is full!"), 0;
case TEAM_IRAN: if(count[2] > count[0] && count[2] > count[1] && count[2] > count[3]) return SendClientMessage(playerid, COLOR_RED, ">>>>This team is full!"), 0;
case TEAM_RUSSIA: if(count[3] > count[0] && count[3] > count[1] && count[3] > count[2]) return SendClientMessage(playerid, COLOR_RED, ">>>>This team is full!"), 0;

}
Reply
#2

Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
Use this simple function to get amount of team variables assigned to players:

ReturnPlayersInTeam(teamid)
{
new t;
for(new a;a<PLAYERS,IsPlayerConnected(a);a++)if(Team[a]==teamid)t++;
return t;
}

It loops connected players then checks the team array against each player and every time a playerid is assigned to a part of the team array it adds 1 to the variable 't' then at the end of the funciton it returns the value of 't', this being the amount of players in the team input.

Then simply use this in a if statement:
if(ReturnPlayersInTeam(0)>ReturnPlayersInTeam(1)) etc...


Hope that helps
so use this for every team ? :


ReturnPlayersInTeam(teamid)
{
new t;
for(new a;a<PLAYERS,IsPlayerConnected(a);a++)if(Team[a]==teamid)t++;
return t;
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)