How to make Team balancer?
#5

try this fixed

if u're using GetPlayerTeam
pawn Код:
#include <a_samp>

#define TEAMA 1
#define TEAMB 2

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, 0xFF0000AA, "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, 0xFF0000AA, "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;
}


and if you're using variables...

pawn Код:
#include <a_samp>

#define TEAMA 1
#define TEAMB 2

new gTeam[MAX_PLAYERS];

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, 0xFF0000AA, "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, 0xFF0000AA, "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: 2 Guest(s)