From 778fdd2f7a611bc3dfdcd9cc81361da08e290322 Mon Sep 17 00:00:00 2001 From: jenz Date: Tue, 14 Apr 2026 15:16:14 +0200 Subject: [PATCH] probably final redux of it --- FakeClients/scripting/FakeClients.sp | 381 ++++++++++++++------------- 1 file changed, 202 insertions(+), 179 deletions(-) diff --git a/FakeClients/scripting/FakeClients.sp b/FakeClients/scripting/FakeClients.sp index ec9a69d..fc963d3 100755 --- a/FakeClients/scripting/FakeClients.sp +++ b/FakeClients/scripting/FakeClients.sp @@ -1,7 +1,6 @@ #include #include #include -#include #include #pragma semicolon 1 @@ -45,7 +44,7 @@ public void OnPluginStart() g_hClanNames = CreateArray(arraySize); g_iAdminFakes = -1; - CreateTimer(20.0, RunPopulationCheck, _, TIMER_REPEAT); + CreateTimer(2.0, RunPopulationCheck, _, TIMER_REPEAT); CreateTimer(3.0, RandomizePing, _, TIMER_REPEAT); CreateTimer(150.0, RandomizeNames, _, TIMER_REPEAT); @@ -189,7 +188,6 @@ public void OnMapEnd() { g_iAdminFakes = -1; } - //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -313,7 +311,7 @@ public Action Command_DebugFakes(int client, int argc) } - ReplyToCommand(client, "[SM] There are currently %d Fake-Clients, from which %d are in Spectate.", iFakes, iFakes - iFakesInTeam); + ReplyToCommand(client, "[SM] There are currently %d Fake-Clients, from which %d are in Spectate. Real Clients %d", iFakes, iFakes - iFakesInTeam, iPlayers); return Plugin_Handled; } @@ -392,186 +390,221 @@ public void OnClientDisconnect(int client) //---------------------------------------------------------------------------------------------------- public void CheckPopulation() { - int iPlayers = 0; + int iPlayersSpectate = 0; + int iPlayersInTeam = 0; + int iFakesSpectate = 0; + int iFakesInTeam = 0; + for(int i = 1; i <= MaxClients; i++) { - if(IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i) && !IsClientAutismBot(i) && !IsClientSourceTV(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR) - iPlayers++; - } - - int iFakesInTeam = 0; - - bool okay_to_change_count = true; - if (iPlayers > 16) - { - iPlayers = 16; - } - int iFakesInTeamNeeded = RoundToFloor(iPlayers / 2.5); - int iFakesNeeded = iPlayers; - - iPlayers = 0; - for(int i = 1; i <= MaxClients; i++) - { - if (IsClientConnected(i)) - iPlayers++; - } - - int iFakes = 0; - for(int i = 1; i <= MaxClients; i++) - { - if (IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) - iFakes++; - } - - if (iPlayers > 53) - { - iFakesInTeamNeeded = 0; - iFakesNeeded = 0; - } - else if (iPlayers > 48 && iFakes > 10) - { - iFakesInTeamNeeded = 3; - iFakesNeeded = 10; - } - else if (iPlayers >= 42) - { - okay_to_change_count = false; - } - - int specs = 0; - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR) + if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i)) { - specs++; - } - } - - //LogMessage("specs: %i", specs); - if (specs >= 14 && iFakesNeeded > 0) - { - iFakesInTeamNeeded = iFakes; - if (iFakes >= 5) - { - iFakesNeeded = iFakesInTeamNeeded = 5; - } - okay_to_change_count = true; - //LogMessage("iFakesInTeamNeeded: %i", iFakesInTeamNeeded); - } - else if (specs <= 9) - { - iFakesInTeamNeeded = (iFakesNeeded / 5); - } - - if (iFakesInTeamNeeded < 0) - { - iFakesInTeamNeeded = 0; - } - - - if (iFakes != iFakesNeeded && okay_to_change_count) - { - if (iFakes < iFakesNeeded) - { - ArrayList hNames = g_hNames.Clone(); - char sName[MAX_NAME_LENGTH]; - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) - { - GetClientName(i, sName, sizeof(sName)); - int iPos = hNames.FindString(sName); - if (iPos > -1) - hNames.Erase(iPos); - } - } - - int iRand = GetRandomInt(0, hNames.Length - 1); - hNames.GetString(iRand, sName, sizeof(sName)); - delete hNames; - - int iIndex = CreateFakeClient(sName); - - if(iIndex < 1 || iIndex > MaxClients) - return; - - SetEntityFlags(iIndex, FL_CLIENT); - DispatchKeyValue(iIndex, "classname", "player"); - DispatchSpawn(iIndex); - - g_iBaseLatency[iIndex] = GetRandomInt(20, 110); - g_iLatency[iIndex] = g_iBaseLatency[iIndex]; - - AdminId FakeAdmin = CreateAdmin(); - SetAdminFlag(FakeAdmin, Admin_Custom6, true); - SetUserAdmin(iIndex, FakeAdmin, true); - - if (GetRandomInt(0, 5) >= 3) + if (!IsFakeClient(i) && !IsClientSourceTV(i)) { - ArrayList hClanNames = g_hClanNames.Clone(); - iRand = GetRandomInt(0, hClanNames.Length - 1); - hClanNames.GetString(iRand, sName, sizeof(sName)); - delete hClanNames; - CS_SetClientClanTag(iIndex, sName); + if (GetClientTeam(i) > CS_TEAM_SPECTATOR) + { + iPlayersInTeam++; + } + else + { + iPlayersSpectate++; + } } else { - CS_SetClientClanTag(iIndex, ""); - } - iFakes++; - } - - if (iFakes > iFakesNeeded) - { - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) - { - g_iLatency[i] = 0; - KickClient(i, "Disconnect by user."); - iFakes--; - break; - } - } - } - } - - for(int i = 1; i <= MaxClients; i++) - { - if (IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) >= CS_TEAM_T) - iFakesInTeam++; - } - - //LogMessage("iFakesInTeam: %i. iFakesInTeamNeeded: %i", iFakesInTeam, iFakesInTeamNeeded); - if (iFakesInTeam != iFakesInTeamNeeded && g_iAdminFakes == -1) - { - if (iFakesInTeam < iFakesInTeamNeeded) - { - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR) + if (GetClientTeam(i) > CS_TEAM_SPECTATOR) { - ChangeClientTeam(i, CS_TEAM_CT); - FakeClientCommandEx(i, "joinclass"); iFakesInTeam++; - break; } - } - } - - if (iFakesInTeam > iFakesInTeamNeeded) - { - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) >= CS_TEAM_T) + else { - ChangeClientTeam(i, CS_TEAM_SPECTATOR); - iFakesInTeam--; - break; + iFakesSpectate++; } } } } + + int iPlayers = iPlayersInTeam + iPlayersSpectate + iFakesInTeam + iFakesSpectate; + if (iPlayers >= 58) + { + if (iFakesInTeam > 0) + { + KickFakeFromTeam(); + } + else if (iFakesSpectate > 1) + { + KickFakeFromSpec(); + } + } + else if (iPlayers >= 48 && iFakesInTeam + iFakesSpectate >= 10) + { + if (iFakesInTeam >= iFakesSpectate >= 0) + { + KickFakeFromTeam(); + } + else if (iFakesSpectate >= iFakesInTeam >= 1) + { + KickFakeFromSpec(); + } + } + else if (iPlayers >= 43 && iFakesInTeam + iFakesSpectate >= 13) + { + if (iFakesInTeam >= iFakesSpectate >= 0) + { + KickFakeFromTeam(); + } + else if (iFakesSpectate >= iFakesInTeam >= 1) + { + KickFakeFromSpec(); + } + } + else if (iPlayers >= 34 && iFakesInTeam + iFakesSpectate >= 16) + { + if (iFakesInTeam >= iFakesSpectate >= 0) + { + KickFakeFromTeam(); + } + else if (iFakesSpectate >= iFakesInTeam >= 1) + { + KickFakeFromSpec(); + } + } + else if (iPlayers <= 32) + { + int some_number = 8; + if (iPlayersSpectate + iPlayersInTeam < some_number * 2) + { + some_number = 4; + } + if (iFakesSpectate + iFakesInTeam < iPlayersSpectate + iPlayersInTeam + some_number) + { + CreateFake(); + some_number = 8; + if (iPlayersSpectate + iFakesSpectate <= some_number * 2) + { + SetFakeToSpectate(); + } + else + { + SetFakeToTeam(); + } + } + else if (iFakesSpectate + iFakesInTeam > iPlayersSpectate + iPlayersInTeam + some_number) + { + if (iPlayersSpectate + iFakesSpectate >= some_number * 2 && iFakesSpectate > 1) + { + KickFakeFromSpec(); + } + else + { + KickFakeFromTeam(); + } + } + } +} + +public void SetFakeToSpectate() +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) >= CS_TEAM_T) + { + ChangeClientTeam(i, CS_TEAM_SPECTATOR); + break; + } + } +} + +public void SetFakeToTeam() +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR) + { + ChangeClientTeam(i, CS_TEAM_CT); + FakeClientCommandEx(i, "joinclass"); + break; + } + } +} + +public void KickFakeFromTeam() +{ + for (int i = 1; i <= MaxClients; i++) + { + if (IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR) + { + g_iLatency[i] = 0; + KickClient(i, "Disconnect by user."); + break; + } + } +} + +public void KickFakeFromSpec() +{ + for (int i = 1; i <= MaxClients; i++) + { + if (IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR) + { + g_iLatency[i] = 0; + KickClient(i, "Disconnect by user."); + break; + } + } +} + +public void CreateFake() +{ + if (g_hNames.Length == 0 || g_hClanNames.Length == 0) + { + return; + } + ArrayList hNames = g_hNames.Clone(); + char sName[MAX_NAME_LENGTH]; + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) + { + GetClientName(i, sName, sizeof(sName)); + int iPos = hNames.FindString(sName); + if (iPos > -1) + hNames.Erase(iPos); + } + } + + int iRand = GetRandomInt(0, hNames.Length - 1); + hNames.GetString(iRand, sName, sizeof(sName)); + delete hNames; + + int iIndex = CreateFakeClient(sName); + + if(iIndex < 1 || iIndex > MaxClients) + return; + + SetEntityFlags(iIndex, FL_CLIENT); + DispatchKeyValue(iIndex, "classname", "player"); + DispatchSpawn(iIndex); + + g_iBaseLatency[iIndex] = GetRandomInt(20, 110); + g_iLatency[iIndex] = g_iBaseLatency[iIndex]; + + AdminId FakeAdmin = CreateAdmin(); + SetAdminFlag(FakeAdmin, Admin_Custom6, true); + SetUserAdmin(iIndex, FakeAdmin, true); + + if (GetRandomInt(0, 5) >= 3) + { + ArrayList hClanNames = g_hClanNames.Clone(); + iRand = GetRandomInt(0, hClanNames.Length - 1); + hClanNames.GetString(iRand, sName, sizeof(sName)); + delete hClanNames; + CS_SetClientClanTag(iIndex, sName); + } + else + { + CS_SetClientClanTag(iIndex, ""); + } } //---------------------------------------------------------------------------------------------------- @@ -592,13 +625,3 @@ public void OnGameFrame() } } } - -/* -public Action ZR_OnClientMotherZombieEligible(int client) -{ - if (IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i)) - return Plugin_Handled; - - return Plugin_Continue; -} -*/