SA-MP Forums Archive
Making a 2Teams (Variables) 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Making a 2Teams (Variables) Balancer (/showthread.php?tid=103230)



Making a 2Teams (Variables) Balancer - aspire5630 - 18.10.2009

Hey i have 2 teams

Код:
new TEAM_COP[MAX_PLAYERIS];
new TEAM_PRIS[MAX_PLAYERS];
and i need to make a team balancer
soo theres not like 15 cops
and like 2 prisoners

Can anyone help?


Re: Making a 2Teams (Variables) Balancer - Donny_k - 19.10.2009

pawn Код:
//where you set teams
if ( team_count_A > team_count_B )
{
  //set to team B
}
else if ( team_count_B > team_count_A )
{
  //set to team A
}
else
{
  //set them to the one they picked
}



Re: Making a 2Teams (Variables) Balancer - aspire5630 - 19.10.2009

Quote:
Originally Posted by Donny
pawn Код:
//where you set teams
if ( team_count_A > team_count_B )
{
  //set to team B
}
else if ( team_count_B > team_count_A )
{
  //set to team A
}
else
{
  //set them to the one they picked
}
I don't quite understand?


Re: Making a 2Teams (Variables) Balancer - aspire5630 - 19.10.2009

**BUMP


Re: Making a 2Teams (Variables) Balancer - saiberfun - 19.10.2009

Quote:
Originally Posted by aspire5630
**BUMP
just check OnPlayerSpawn or where u want to check that
if team got more player or if team b got more
if yes set the player to the other team or whatever u want to do then
to check how much ppl are on the team ull need to make a loop
which goes through ur maxplayers n check everyone if they are on team a or team b
(u need 2 new variables in the loop one for team a and one for b) then if the player it just loops through is team a it sets variable a++;
and if he is team b it sets variable b++;
after that it should check what i explained above



Re: Making a 2Teams (Variables) Balancer - kman - 19.10.2009

what do you mean like if there are 15 cops and 10 prisoners it auto makes you prisoner because too much cops


Re: Making a 2Teams (Variables) Balancer - aspire5630 - 19.10.2009

yeh, what it will do

say..

4 prisoners...
it will make the next people who log on
Cops

Just to balance the teams


Re: Making a 2Teams (Variables) Balancer - saiberfun - 19.10.2009

Quote:
Originally Posted by aspire5630
yeh, what it will do

say..

4 prisoners...
it will make the next people who log on
Cops

Just to balance the teams
Quote:
Originally Posted by ┤ŞąiBЄЯҒПŋ├
Quote:
Originally Posted by aspire5630
**BUMP
just check OnPlayerSpawn or where u want to check that
if team got more player or if team b got more
if yes set the player to the other team or whatever u want to do then
to check how much ppl are on the team ull need to make a loop
which goes through ur maxplayers n check everyone if they are on team a or team b
(u need 2 new variables in the loop one for team a and one for b) then if the player it just loops through is team a it sets variable a++;
and if he is team b it sets variable b++;
after that it should check what i explained above



Re: Making a 2Teams (Variables) Balancer - Enzo_Ferrari_V12 - 20.10.2009

Код:
//top
new team_count_A;
new team_count_B;

//OnPlayerRequestSpawn
if ( team_count_A > team_count_B )
{
  //deny team A and set to team B
}
else if ( team_count_B > team_count_A )
{
  //deny team B and set to team A
}
else
{
  //set them to the one they picked
}

//OnPlayerSpawn

If(gTeam=TEAM_COP)
{
//add the value "1" to the variable new team_count_A;
}
else if(gTeam=TEAM_PRIS)
{
//add the value "1" to the variable new team_count_B;
}

//OnPlayerDisconnect

If(gTeam=TEAM_COP)
{
//subtractthe value "1" to the variable new team_count_A;
}
else if(gTeam=TEAM_PRIS)
{
//subtract the value "1" to the variable new team_count_B;
}



Re: Making a 2Teams (Variables) Balancer - saiberfun - 20.10.2009

Quote:
Originally Posted by [KG
Nikere ]
Код:
//top
new team_count_A;
new team_count_B;

//OnPlayerRequestSpawn
if ( team_count_A > team_count_B )
{
  //deny team A and set to team B
}
else if ( team_count_B > team_count_A )
{
  //deny team B and set to team A
}
else
{
  //set them to the one they picked
}

//OnPlayerSpawn

If(gTeam=TEAM_COP)
{
//add the value "1" to the variable new team_count_A;
}
else if(gTeam=TEAM_PRIS)
{
//add the value "1" to the variable new team_count_B;
}

//OnPlayerDisconnect

If(gTeam=TEAM_COP)
{
//subtractthe value "1" to the variable new team_count_A;
}
else if(gTeam=TEAM_PRIS)
{
//subtract the value "1" to the variable new team_count_B;
}
u guys forget the loop



pawn Код:
//OntopOfScript
new team1count,team2count;


//OnPlayerREquestSpawn/Sumwhere in script
OnPlayerRequestSpawn(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
      if(GetPlayerTeam(i) == GTEAM_ONE)
      {
      team1count++;
      }
      if(GetPlayerTeam(i) == GTEAM_TWO)
      {
      team2count++;
      }
    }
    if(team1count > team2count)
    {
      SetPlayerTeam(playerid,2);
    }
    if(team2count > team1count)
    {
      SetPlayerTeam(playerid,1);
    }
    if(team2count == team1count)
    {
     //Set the Selected Team(however u want to do it.
    }
}