new team1 = GetPlayersInTeamFromMaxPlayers(1);//team1 = how many players are in TEAM_ONE..
new team2 = GetPlayersInTeamFromMaxPlayers(2);//team2 = how many players are in TEAM_TWO..
if(team1 > team2 && GetPlayerTeam(playerid) == 1)//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 && GetPlayerTeam(playerid) == 2)//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..
}
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..
}
GetPlayerTeam(playerid) == 1)
if(team1 > team2 && GetPlayerTeam(playerid) == 1)
If you already gave team1/2 a value. Then isn' t the
pawn Код:
pawn Код:
|
public AutoAssign(playerid)
{
new RedCount, BlueCount;
for(new i=0; i<GetMaxPlayers(); i++)
{
switch(GetPlayerTeam[i])
{
case Team1: RedCount++;
case Team2: BlueCount++;
}
}
if(RedCount > BlueCount)
{
return Team2;
}
if(BlueCount > RedCount)
{
return Team1;
}
if(BlueCount == RedCount)
{
new decide = random(2);
switch(decide)
{
case 0: return Team1;
case 1: return Team2;
}
}
return 0;
}
public OnPlayerRequestSpawn(playerid)
{
new T_PLAYERS;
T_PLAYERS = GetTeamWithLeastPlayers();
if(GetPlayerTeam(playerid) == T_PLAYERS || T_PLAYERS == -1) return true;
else GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Another Team!", 3000, 5);
return false;
}
stock GetTeamWithLeastPlayers()
{
new T0, T1;
for(new i = 0; i < MAX_PLAYERS; i++)
{
//if(!IsPlayerConnected(i)) continue;
if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
switch(gTeam[i])
{
case 0: T0++;
case 1: T1++;
}
}
if(T0 < T1) return 0;
else if(T0 > T1) return 1;
return -1;
}