I'm going to explain how to limit max players per team according to the number of them.
1. We need <a_samp> and <foreach> includes.
2. We need already the teams defined and also the player classes added below OnGameModeInit - OnPlayerRequestClass - The variable to set the player team. in this case gTeam[MAX_PLAYERS];
PHP Code:
#define TEAM_A 0
#define TEAM_B 1
#define TEAM_C 2
new gTeam[MAX_PLAYERS];
public OnPlayerRequestClass(playerid, classid)
{
switch(classid)
{
case 0:
{
SendClientMessage(playerid, -1, "TEAM A");
SetPlayerSkin(playerid, 0);
}
case 1:
{
SendClientMessage(playerid, -1, "TEAM B");
SetPlayerSkin(playerid, 1);
}
case 2:
{
SendClientMessage(playerid, -1, "TEAM C");
SetPlayerSkin(playerid, 2);
}
}
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnGameModeInit()
{
AddPlayerClass(0,1958.3783, 1343.1572, 15.3746,94.4754,0,0,0,0,0,0);
AddPlayerClass(1,1958.3783, 1343.1572, 15.3746,94.4754,0,0,0,0,0,0);
AddPlayerClass(2,1958.3783, 1343.1572, 15.3746,94.4754,30,500,29,200,1,1);
return 1;
}
3. We are going to create a stock that is going to return the number of players of the team indicated.
PHP Code:
public OnPlayerRequestSpawn(playerid)//Calling this function which gets called when a player tries to spawn
{
new acount = GetTeamCount(TEAM_A);//Placing the count of TEAM_A to acount
new bcount = GetTeamCount(TEAM_B);//Placing the count of TEAM_B to bcount
new ccount = GetTeamCount(TEAM_C);//Placing the count of TEAM_C to ccount
switch(gTeam[playerid])//disaggregating the cases of gTeam - we have 3 teams therefore 3 cases.
{
case TEAM_A://TEAM_A case
{
if(acount > bcount && ccount)//If the count of players in TEAM_A is greater than the count of TEAM_B and TEAM_C
{
SendClientMessage(playerid, -1, "ERROR: Team A is full. Join another team.");//Sending the error message
return 0;//Can't spawn. - Must choose another team.
}
}
case TEAM_B://TEAM_B case
{
if(bcount > acount && ccount )//If the count of players in TEAM_B is greater than the count of TEAM_A and TEAM_C
{
SendClientMessage(playerid, -1,"ERROR: Team B is full. Join another team.");//Sending the error message
return 0;//Can't spawn - Must choose another team.
}
}
case TEAM_C://TEAM_C case
{
if(ccount > acount && bcount)//If the count of players in TEAM_C is greater than the count of TEAM_A and TEAM_B
{
SendClientMessage(playerid, -1, "ERROR: Team C is full. Join another team.");//Sending the error message
return 0;//Can't spawn - Must choose another team
}
}
}
return 1;//Can spawn..
}
Thanks.