21.11.2009, 10:42
pawn Код:
stock GetPlayersInTeam(teamid)
{
new playersInTeam = 0;
for(new i=0;i<MAX_PLAYERS<i++;)
{
if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid) playersInTeam++;
}
return playersInTeam;
}
Example: you can create a team balancer if you're using SetPlayerTeam, not variables.
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new pClass = GetPlayerSkin(playerid);
switch(pClass)
{
case 1,2,3: SetPlayerTeam(playerid,1);
case 4,5,6: SetPlayerTeam(playerid,2);
}
if(GetPlayerTeam(playerid) == 1 && GetPlayersInTeam(1) > GetPlayersInTeam(2))
{
SendClientMessage(playerid,color,"Team 1 is full, please choose another team/skin/class.");
return 0;
}
else if(GetPlayerTeam(playerid) == 2 && GetPlayersInTeam(1) < GetPlayersInTeam(2))
{
SendClientMessage(playerid,color,"Team 2 is full, please choose another team/skin/class.");
return 0;
}
return 1;
}