Quote:
Originally Posted by ReD_HunTeR
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; }
|
There's no need to loop through all the players just to see how much of them are on a specific team, you could just use a variable as an accumulator:
pawn Код:
new gTeam1,
gTeam2,
pTeam[MAX_PLAYERS];
public OnPlayerDisconnect(playerid, reason)
{
if(pTeam[playerid] == 1) gTeam1 --;
else gTeam2 --;
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
if(pTeam[playerid] == 1)
{
gTeam1 --;
pTeam[playerid] = 0;
}
else if(pTeam[playerid] == 2)
{
gTeam2 --;
pTeam[playerid] = 0;
}
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
if(gTeam1 <= gTeam2)
{
GameTextForPlayer(playerid, "~r~Team 1 is full!~n~~w~Choose another team!", 3000, 5);
SendClientMessage(playerid, 0xFF0000AA, "Please choose another team because team 1 is full.");
return 0;
}
else
{
GameTextForPlayer(playerid, "~r~Team 2 is full!~n~~w~Choose another team!", 3000, 5);
SendClientMessage(playerid, 0xFF0000AA, "Please choose another team because team 2 is full.");
return 0;
}
return 1;
}
public OnPlayerSpawn(playerid)
{
if(gTeam1 <= gTeam2)
{
SendClientMessage(playerid, -1 "You have joined team 1!");
pTeam[playerid] = 1;
gTeam1 ++;
}
else
{
SendClientMessage(playerid, -1 "You have joined team 2!");
pTeam[playerid] = 2;
gTeam2 ++;
}
return 1;
}
CMD:balanceteams(playerid, params[])
{
SendClientMessageToAll(-1, "An administrator has balanced the teams!");
gTeam1 = 0, gTeam2 = 0;
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(gTeam1 <= gTeam2)
{
SendClientMessage(playerid, -1 "You have joined team 1!");
pTeam[playerid] = 1;
gTeam1 ++;
}
else
{
SendClientMessage(playerid, -1 "You have joined team 2!");
pTeam[playerid] = 2;
gTeam2 ++;
}
}
return 1;
}