Team Balance - 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 Balance (
/showthread.php?tid=296611)
Team Balance -
vassilis - 12.11.2011
well the tittle say it all.Firstly hey all after lot effor and spent time for my released gamemode named Adrenaline stunt world(See in my signature)i am working on a new tdm gamemode with 2 basic teams
i wander how i can make a team balancer..so when a team has more players that the other one then it will return him to the selection menu..
![Cheesy](images/smilies/biggrin.png)
Regards,
Blacklisted_Bboy
Re: Team Balance -
CyNiC - 12.11.2011
Did you searched for?
pawn Code:
//[Tutorial] Simple Team Balancer [SA-MP] @ http://www.devshack.info - Tutorial by Weponz Inc. © 2010 - 2011#include <a_samp>//If i need to explain this to you, may god have mercy on your soul..//-----------------------------------[STEP 1]---------------------------------////Ok, Im going to use two teams for this tutorial, TEAM_ONE & TEAM_TWO,//you could simply add more later. Type the following below:#define TEAM_ONE 0#define TEAM_TWO 1//-----------------------------------[STEP 2]---------------------------------////Ok, now we have defined our teams(classes) we need to make a variable//that checks the players team, so we can use a function(shown below)//later to check there team, type the following below:static gTeam
[MAX_PLAYERS
];
//Yes its very common..//Now we can use gTeam[playerid] == TEAM_ONE or gTeam[playerid] == TEAM_TWO..//-----------------------------------[STEP 2]---------------------------------////Now, we need to create a stock which loops through MAX_PLAYERS, counting//how many online players are in our specified team, returning a player count//as an integra(number), This stock was developed by myself so keep my credits!//i will show you below how it works:stock GetPlayersInTeamFromMaxPlayers
(teamid
)//Stock developed by Weponz (Weponz Inc. © 2010 - 2011){ new playercount
= 0;
//Set our count to 0 as we have not counted any players yet.. for(new i
= 0; i
< MAX_PLAYERS; i
++)//Loop through MAX_PLAYERS(I suggest you redefine MAX_PLAYERS to ensure max efficency).. { if(GetPlayerState
(i
) == PLAYER_STATE_NONE
) continue;
//If a player is in class selection continue.. if(gTeam
[i
] != teamid
) continue;
//If a player is NOT in the specified teamid continue.. playercount
++;
//else (there in the teamid) so count the player in the team.. } return playercount;
//Return the total players counted in the specified team..}//-----------------------------------[STEP 3]---------------------------------////Ok, now we can count how many players are in w/e team we check//with our new function GetPlayersInTeamFromMaxPlayers(teamid) we can now//check for team in-balance under OnPlayerRequestSpawn as its most efficent..public OnPlayerRequestSpawn
(playerid
){ new team1
= GetPlayersInTeamFromMaxPlayers
(TEAM_ONE
);
//team1 = how many players are in TEAM_ONE.. new team2
= GetPlayersInTeamFromMaxPlayers
(TEAM_TWO
);
//team2 = how many players are in TEAM_TWO.. if(team1
> team2
&& gTeam
[playerid
] == TEAM_ONE
)//if team1 has more players than team2 and the player is trying to spawn as TEAM_ONE.. { GameTextForPlayer
(playerid,
"~r~Team Full!~n~~w~Choose Another Team!",
3000,
5);
//Tell them its full, choose another team.. return 0;
//And stop them from spawning.. } else if(team2
> team1
&& gTeam
[playerid
] == TEAM_TWO
)//if team2 has more players than team1 and the player is trying to spawn as TEAM_TWO.. { GameTextForPlayer
(playerid,
"~r~Team Full!~n~~w~Choose Another Team!",
3000,
5);
//Tell them its full, choose another team.. return 0;
//And stop them from spawning.. } return 1;
}//Bang, you now have a team balancer.//Enjoy,//-------------------------------[End OF Tutorial]----------------------------////Tutorial by Weponz Inc. © 2010 - 2011
Other:
https://sampforum.blast.hk/showthread.php?tid=224853
And:
https://sampforum.blast.hk/showthread.php?tid=181887
Re: Team Balance -
vassilis - 12.11.2011
oh damn it was ateam balancer tutorial out there?? pff thx man
Re: Team Balance -
Shoulen - 12.11.2011
Create a variable for each time, like Team1 and Team2
Code:
new Team1;
new Team2;
And every time you assign a player to a team add 1 to the variable and every time you remove a player from a team, subtract 1 from that specific team
And from there make sure there is in imbalance, so if you only want to let the teams have 2 more players than each other before auto balance commences then do something like
Code:
new check = Team1 + 2;
If(check > Team2) {
// Autobalance
}
check = Team2 + 2;
else if(check > Team1) {
// Autobalance
}
I hope that works, it's untested.
Bottom line is you need to run checks to compare them as a ratio.
EDIT: If mine doesn't work just follow the above Tutorial....
- Shoulen