diff --git a/FakeClients/scripting/FakeClients.sp b/FakeClients/scripting/FakeClients.sp index 6f4b35e..825df22 100755 --- a/FakeClients/scripting/FakeClients.sp +++ b/FakeClients/scripting/FakeClients.sp @@ -332,194 +332,140 @@ public void OnClientDisconnect(int client) //---------------------------------------------------------------------------------------------------- public void CheckPopulation() { - g_bCheckRequested = false; + g_bCheckRequested = false; - if(g_bMapEnded) - return; + if(g_bMapEnded) + return; - int iPlayers = GetClientCount(false); + int iPlayers = GetClientCount(false); - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientConnected(i) && IsFakeClient(i)) - iPlayers--; - } + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i) && IsFakeClient(i)) + iPlayers--; + } - bool bServerDying; - if(iPlayers < (g_iPopulation - 10)) - bServerDying = true; + int iFakes = 0; + int iFakesInTeam = 0; - int iFakes = 0; - int iFakesInTeam = 0; + for(int i = 1; i <= MaxClients; i++) + { + if (g_bFakePopulation[i]) + iFakes++; + } - for(int i = 1; i <= MaxClients; i++) - { - if (g_bFakePopulation[i]) - iFakes++; - } + int iFakesNeeded = 0; + int iFakesInTeamNeeded = 0; + + //24 to account for 4 autismbots. + iFakesNeeded = 24 - RoundToFloor(iPlayers / 1.5); + if (iFakesNeeded < 0) + { + iFakesNeeded = 0; + iFakesInTeamNeeded = 0; + } + else + { + iFakesInTeamNeeded = iFakesNeeded / 3; + } - int iFakesNeeded = 0; - int iFakesInTeamNeeded = 0; + if(g_iAdminFakes != -1) + iFakesNeeded = g_iAdminFakes; - if(bServerDying) - { - if (iPlayers > 45) - { - iFakesNeeded = 6; - iFakesInTeamNeeded = 2; - } - else if (iPlayers > 20) - { - iFakesNeeded = 7; - iFakesInTeamNeeded = 3; - } - else if (iPlayers > 10) - { - iFakesNeeded = 6; - iFakesInTeamNeeded = 2; - } - else - { - iFakesNeeded = 5; - iFakesInTeamNeeded = 0; - } - } - else - { - if (iPlayers > 61) - { - iFakesNeeded = 0; - iFakesInTeamNeeded = 0; - } - else if(iPlayers > 59) - { - iFakesNeeded = 1; - iFakesInTeamNeeded = 0; - } - else if(iPlayers > 57) - { - iFakesNeeded = 2; - iFakesInTeamNeeded = 1; - } - else if(iPlayers > 55) - { - iFakesNeeded = 3; - iFakesInTeamNeeded = 1; - } - else if (iPlayers > 20) - { - iFakesNeeded = 5; - iFakesInTeamNeeded = 2; - } - else if (iPlayers > 10) - { - iFakesNeeded = 5; - iFakesInTeamNeeded = 1; - } - else - { - iFakesNeeded = 5; - iFakesInTeamNeeded = 0; - } - } + if (iFakes != iFakesNeeded) + { + while (iFakes < iFakesNeeded && !g_bBlockInstantFakeConnects) + { + ArrayList hNames = g_hNames.Clone(); + char sName[MAX_NAME_LENGTH]; + for(int i = 1; i <= MaxClients; i++) + { + if(g_bFakePopulation[i]) + { + GetClientName(i, sName, sizeof(sName)); + int iPos = hNames.FindString(sName); + if (iPos > -1) + hNames.Erase(iPos); + } + } - if(g_iAdminFakes != -1) - iFakesNeeded = g_iAdminFakes; + int iRand = GetRandomInt(0, hNames.Length - 1); + hNames.GetString(iRand, sName, sizeof(sName)); + delete hNames; - if (iFakes != iFakesNeeded) - { - while (iFakes < iFakesNeeded && !g_bBlockInstantFakeConnects) - { - ArrayList hNames = g_hNames.Clone(); - char sName[MAX_NAME_LENGTH]; - for(int i = 1; i <= MaxClients; i++) - { - if(g_bFakePopulation[i]) - { - GetClientName(i, sName, sizeof(sName)); - int iPos = hNames.FindString(sName); - if (iPos > -1) - hNames.Erase(iPos); - } - } + int iIndex = CreateFakeClient(sName); - int iRand = GetRandomInt(0, hNames.Length - 1); - hNames.GetString(iRand, sName, sizeof(sName)); - delete hNames; + if(iIndex < 1 || iIndex > MaxClients) + return; - int iIndex = CreateFakeClient(sName); + SetEntityFlags(iIndex, FL_CLIENT); + DispatchKeyValue(iIndex, "classname", "player"); + DispatchSpawn(iIndex); - if(iIndex < 1 || iIndex > MaxClients) - return; + g_bFakePopulation[iIndex] = true; + g_iBaseLatency[iIndex] = GetRandomInt(20, 110); + g_iLatency[iIndex] = g_iBaseLatency[iIndex]; - SetEntityFlags(iIndex, FL_CLIENT); - DispatchKeyValue(iIndex, "classname", "player"); - DispatchSpawn(iIndex); + AdminId FakeAdmin = CreateAdmin(); + SetAdminFlag(FakeAdmin, Admin_Custom6, true); + SetUserAdmin(iIndex, FakeAdmin, true); + //CS_SetClientClanTag(iIndex, "UNLOZE"); + iFakes++; - g_bFakePopulation[iIndex] = true; - g_iBaseLatency[iIndex] = GetRandomInt(20, 110); - g_iLatency[iIndex] = g_iBaseLatency[iIndex]; + g_bBlockInstantFakeConnects = true; + } - AdminId FakeAdmin = CreateAdmin(); - SetAdminFlag(FakeAdmin, Admin_Custom6, true); - SetUserAdmin(iIndex, FakeAdmin, true); - //CS_SetClientClanTag(iIndex, "UNLOZE"); - iFakes++; + while (iFakes > iFakesNeeded) + { + for(int i = 1; i <= MaxClients; i++) + { + if(g_bFakePopulation[i]) + { + g_bFakePopulation[i] = false; + g_iLatency[i] = 0; + KickClient(i, "Disconnect by user."); + iFakes--; + break; + } + } + } + } - g_bBlockInstantFakeConnects = true; - } + for(int i = 1; i <= MaxClients; i++) + { + if (g_bFakePopulation[i] && GetClientTeam(i) >= CS_TEAM_T) + iFakesInTeam++; + } - while (iFakes > iFakesNeeded) - { - for(int i = 1; i <= MaxClients; i++) - { - if(g_bFakePopulation[i]) - { - g_bFakePopulation[i] = false; - g_iLatency[i] = 0; - KickClient(i, "Disconnect by user."); - iFakes--; - break; - } - } - } - } + if (iFakes == iFakesNeeded && iFakesInTeam != iFakesInTeamNeeded && g_iAdminFakes == -1) + { + while (iFakesInTeam < iFakesInTeamNeeded) + { + for(int i = 1; i <= MaxClients; i++) + { + if(g_bFakePopulation[i] && GetClientTeam(i) <= CS_TEAM_SPECTATOR) + { + ChangeClientTeam(i, CS_TEAM_CT); + FakeClientCommandEx(i, "joinclass"); + iFakesInTeam++; + break; + } + } + } - for(int i = 1; i <= MaxClients; i++) - { - if (g_bFakePopulation[i] && GetClientTeam(i) >= CS_TEAM_T) - iFakesInTeam++; - } - - if (iFakes == iFakesNeeded && iFakesInTeam != iFakesInTeamNeeded && g_iAdminFakes == -1) - { - while (iFakesInTeam < iFakesInTeamNeeded) - { - for(int i = 1; i <= MaxClients; i++) - { - if(g_bFakePopulation[i] && GetClientTeam(i) <= CS_TEAM_SPECTATOR) - { - ChangeClientTeam(i, CS_TEAM_CT); - FakeClientCommandEx(i, "joinclass"); - iFakesInTeam++; - break; - } - } - } - - while (iFakesInTeam > iFakesInTeamNeeded) - { - for(int i = 1; i <= MaxClients; i++) - { - if(g_bFakePopulation[i] && GetClientTeam(i) >= CS_TEAM_T) - { - ChangeClientTeam(i, CS_TEAM_SPECTATOR); - iFakesInTeam--; - break; - } - } - } - } + while (iFakesInTeam > iFakesInTeamNeeded) + { + for(int i = 1; i <= MaxClients; i++) + { + if(g_bFakePopulation[i] && GetClientTeam(i) >= CS_TEAM_T) + { + ChangeClientTeam(i, CS_TEAM_SPECTATOR); + iFakesInTeam--; + break; + } + } + } + } } //----------------------------------------------------------------------------------------------------