Helllo I am trying to make simple ratio system, but I don't know how to avoid random team pick on map start, if you didn't choose team it automatically assign you to T/CT and ignores "jointeam", thanks for ideas.
PHP Code:
#define RATIO 1
public OnPluginStart()
{
AddCommandListener(Listener_JoinTeam, "jointeam");
}
public Action jointeam(int client, int args)
{
int teamRatio = RATIO;
if (!client || !IsClientInGame(client) || IsFakeClient(client))
{
return Plugin_Continue;
}
char teamString[3];
GetCmdArg(1, teamString, sizeof(teamString));
int newTeam = StringToInt(teamString);
int oldTeam = GetClientTeam(client);
if (newTeam == CS_TEAM_CT && oldTeam != CS_TEAM_CT)
{
int countTs = 0;
int countCTs = 0;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
if (GetClientTeam(i) == CS_TEAM_T)
{
countTs++;
}
if (GetClientTeam(i) == CS_TEAM_CT)
{
countCTs++;
}
}
}
if (countCTs < ((countTs) / teamRatio) || !countCTs)
{
return Plugin_Continue;
}
else
{
ClientCommand(client, "play ui/freeze_cam.wav");
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public OnClientDisconnect(client)
{
if (GetClientTeam(client) == CS_TEAM_T)
{
int countTs = 0;
int countCTs = 0;
int lowestCTtime = 0;
float timeCTs = 0.0;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
float time = GetClientTime(client);
if (GetClientTeam(i) == CS_TEAM_T)
{
countTs++;
}
if (GetClientTeam(i) == CS_TEAM_CT)
{
if (time < timeCTs || timeCTs == 0.0)
{
lowestCTtime = i;
timeCTs == time;
}
countCTs++;
}
}
}
if (countCTs > ((countTs ) / RATIO))
{
if(lowestCTtime != 0)
{
ChangeClientTeam(lowestCTtime, CS_TEAM_T);
}
}
}
}
__________________