How to make Team balancer?
#2

if you're using GetPlayerTeam

pawn Код:
#define TEAMA 1
#define TEAMB 2

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && gTeam[playerid] == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && gTeam[playerid] == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(GetPlayerTeam(i) != teamid) continue;
        playercount++;
    }
    return playercount;
}

if you're using array, variables..
pawn Код:
#define TEAMA 1
#define TEAMB 2

new gTeam[MAX_PLAYERS];

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && GetPlayerTeam(playerid) == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && GetPlayerTeam(playerid) == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(gTeam[i] != teamid) continue;
        playercount++;
    }
    return playercount;
}
Reply


Messages In This Thread
How to make Team balancer? - by Fantje - 21.03.2015, 17:06
Re: How to make Team balancer? - by ReD_HunTeR - 21.03.2015, 17:25
Re: How to make Team balancer? - by SickAttack - 21.03.2015, 17:31
Re: How to make Team balancer? - by Fantje - 21.03.2015, 17:41
Re: How to make Team balancer? - by ReD_HunTeR - 21.03.2015, 18:34
Re: How to make Team balancer? - by SickAttack - 21.03.2015, 18:39
Re: How to make Team balancer? - by Fantje - 21.03.2015, 18:59
Re: How to make Team balancer? - by SickAttack - 21.03.2015, 19:01
Re: How to make Team balancer? - by Fantje - 21.03.2015, 19:05
Re: How to make Team balancer? - by SickAttack - 21.03.2015, 19:15

Forum Jump:


Users browsing this thread: 3 Guest(s)