22.11.2015, 05:15
Hello! I can only create a team balancer for two teams, but how about a team balancer for four teams? Can someone demonstrate a sample code for me (or a code structure to follow)? Thanks!
#define TEAM1 0
#define TEAM2 1
#define TEAM3 2
#define TEAM4 3
new gTeam[MAX_PLAYERS];
public OnPlayerRequestClass(playerid, classid)
{
switch(classid)
{
case 0: { gTeam[playerid] = TEAM1; SetPlayerTeam(playerid, 0); }
case 1: { gTeam[playerid] = TEAM2; SetPlayerTeam(playerid, 1); }
case 2: { gTeam[playerid] = TEAM3; SetPlayerTeam(playerid, 2); }
case 3: { gTeam[playerid] = TEAM4; SetPlayerTeam(playerid, 3); }
}
return 1;
}
stock GetPlayersCountInTeam(teamid)
{
new playercount = 0;
for(new x = 0; x < MAX_PLAYERS; x ++)
{
if(GetPlayerState(x) == PLAYER_STATE_NONE) continue;
if(GetPlayerTeam(x) != teamid) continue;
playercount++;
}
return playercount;
}
public OnPlayerRequestSpawn(playerid)
{
new team1count = GetPlayersCountInTeam(TEAM1);
new team2count = GetPlayersCountInTeam(TEAM2);
new team3count = GetPlayersCountInTeam(TEAM3);
new team4count = GetPlayersCountInTeam(TEAM4);
switch(gTeam[playerid])
{
case TEAM1:
{
if(team1count > team2count && team3count && team4)
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0;
}
}
case TEAM2:
{
if(team2count > team1count && team3count && team4)
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0;
}
}
case TEAM3:
{
if(team3count > team1count && team2count && team4)
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0;
}
}
case TEAM4:
{
if(team4count > team1count && team2count && team3)
{
SendClientMessage(playerid, 0xFF0000FF,"This team is currently full!");
return 0;
}
}
}
return 1;
}
Credits? For something that isn't going to work like he wants it to?
|
OnPlayerConnect...
new online = Iter_Count(Player)...
online /= NUMBER_OF_TEAMS...
new count;
foreach(new i: Player) {
SetPlayerTeam(i, count % NUMBER_OF_TEAMS);
count++;
}