team balance -
BlackWolf120 - 23.02.2011
hi,
theres sth. wrong with this team balance code.
If there are 2 members in the police team and i wanna join the other team it says team full but this team is empty and the other team is bigger. So wheres the problem.
It seems correct to me
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new Count1, Count2;
for(new p = 0; p < GetMaxPlayers(); p++)
{
if (GetPlayerTeam(p) == TEAM_POLICE) Count1++;
else if (GetPlayerTeam(p) == TEAM_TERRORISTS) Count2++;
}
if ((Count1 > Count2) && GetPlayerTeam(playerid) == TEAM_TERRORISTS)
{
GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
PlayerPlaySound(playerid,1055,0, 0, 0);
return 0;
}
else if ((Count2 > Count1) && GetPlayerTeam(playerid) == TEAM_POLICE)
{
GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
PlayerPlaySound(playerid,1055,0, 0, 0);
return 0;
}
}
Re: team balance -
Hashski - 23.02.2011
Код:
public OnPlayerRequestSpawn(playerid)
{
new Count1, Count2;
for(new p = 0; p < GetMaxPlayers(); p++)
{
if (GetPlayerTeam(p) == TEAM_POLICE) Count1++;
else if (GetPlayerTeam(p) == TEAM_TERRORISTS) Count2++;
}
if ((Count1 > Count2) && GetPlayerTeam(playerid) == TEAM_TERRORISTS)
{
GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
PlayerPlaySound(playerid,1055,0, 0, 0);
return 0;
}
else if ((Count2 < Count1) && GetPlayerTeam(playerid) == TEAM_POLICE)
{
GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
PlayerPlaySound(playerid,1055,0, 0, 0);
return 0;
}
}
Test that..?
Re: team balance -
Serbish - 23.02.2011
pawn Код:
// At the top of the script.
new Count_Police;
new Count_Terrorists;
// --------------------------------------
public OnPlayerRequestSpawn(playerid)
{
if((Count_Police > Count_Terrorists) && GetPlayerTeam(playerid) == TEAM_POLICE)
{
GameTextForPlayer(playerid, "~r~Police team is full!", 600, 5);
PlayerPlaySound(playerid,1055,0, 0, 0);
return 0;
}
if((Count_Police < Count_Terrorists) && GetPlayerTeam(playerid) == TEAM_TERRORISTS)
{
GameTextForPlayer(playerid, "~r~Terrorists team is full!", 600, 5);
PlayerPlaySound(playerid,1055,0, 0, 0);
return 0;
}
if(GetPlayerTeam(playerid) == TEAM_POLICE)
{
Count_Police++;
}
else if(GetPlayerTeam(playerid) == TEAM_TERRORISTS)
{
Count_Terrorists++;
}
return 1;
}
I did some important changes, now it should work fine.
EDIT:
Also make sure when a player disconnects to reduce the amount of their team.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(GetPlayerTeam(playerid) == TEAM_POLICE)
{
Count_Police--;
}
else if(GetPlayerTeam(playerid) == TEAM_TERRORISTS)
{
Count_Terrorists--;
}
return 1;
}
Re: team balance -
BlackWolf120 - 23.02.2011
thank you alot for ur code.
Im gonna test it as soon as i got enough players.
thx, hope this is working
Re: team balance -
BlackWolf120 - 08.03.2011
hi,
no, this does not work like it should yet.
But were trying to fix it
regards...
Re: team balance -
Roperr - 07.10.2011
new Team1;
new Team2;
new Team3;
new Team4;
OnPlayerSpawn use
if(gTeam[playerid] == (your team here) )
{
Team1++;
// ADD THIS FOR ALL THE TEAMS YOU HAVE, Team2, Team3, Team4
}
OnPlayerDeath use
if(gTeam[playerid] == (your team here) )
{
Team1--;
// ADD THIS FOR ALL THE TEAMS YOU HAVE, Team2, Team3, Team4
}
OnPlayerRequestSpawn use
public OnPlayerRequestSpawn(playerid)
{
if(Team1 > Team2 || Team1 > Team3 || Team1 > Team4) return GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
if(Team2 > Team1 || Team2 > Team3 || Team2 > Team4) return GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
if(Team3 > Team1 || Team3 > Team2 || Team3 > Team4) return GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
if(Team4 > Team1 || Team4 > Team2 || Team4 > Team3) return GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
return 1;
}