majorly redid fakeclients behaviour to be balanced, updated knockback modifier to only consider mapcooldowns of over 60 hours and to check the timeleft on maps to prevent triggering the condition hopefully too early

This commit is contained in:
jenz 2026-04-17 20:15:42 +02:00
parent 7d5e56540a
commit f37711fbdf
2 changed files with 112 additions and 178 deletions

View File

@ -1,5 +1,4 @@
#include <sourcemod>
#include <BotTargeting>
#include <cstrike>
#include <mapchooser_extended>
@ -10,7 +9,7 @@ public Plugin myinfo =
name = "knockback low pop modifier",
author = "jenz",
description = "balances knockback for low population",
version = "1.0.0",
version = "1.1.0",
url = ""
}
@ -42,7 +41,7 @@ public void OnMapStart()
{
//Decided for now to exclude MaxPlayers
//MaxTime, MinTime, MinPlayers, CooldownTime, MinHoursAvg
if (GetMapMaxTime(map) != 0 || GetMapMinTime(map) != 0 || GetMapMinPlayers(map) != 0 /*|| GetMapMaxPlayers(map) != 0*/ || GetMapCooldownTime2(map) > 60
if (GetMapMaxTime(map) != 0 || GetMapMinTime(map) != 0 || GetMapMinPlayers(map) != 0 || GetMapCooldownTime2(map) > 60
|| GetMapMinHoursAvg(map) != 0)
{
g_bDoingMapTouristMode = true;
@ -52,56 +51,55 @@ public void OnMapStart()
public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
if (CS_GetTeamScore(CS_TEAM_T) == 0 && CS_GetTeamScore(CS_TEAM_CT) == 0)
ServerCommand("zr_class_set_multiplier zombies knockback 1.0");
ServerCommand("sm_iammo @all 0");
int TimeLeft;
if (GetMapTimeLeft(TimeLeft) && TimeLeft < 0)
{
return;
}
int active_player_count = 0;
for (int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i) && !IsClientAutismBot(i) && !IsClientSourceTV(i))
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
{
active_player_count++;
}
}
int choosen_number = 24;
int choosen_number = 14;
if (active_player_count < choosen_number)
{
int zombie_ratio = GetConVarInt(FindConVar("zr_infect_mzombie_ratio"));
int infectectable_players = 0;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR)
{
infectectable_players++;
}
}
float knockback_increase = float(zombie_ratio) / float(active_player_count);
float knockback_increase = float(zombie_ratio) / float(infectectable_players);
if (knockback_increase > 3.0)
knockback_increase = 3.0;
else if(knockback_increase < 1.0)
knockback_increase = 1.0
if (knockback_increase > 1.0 || (g_bDoingMapTouristMode && active_player_count < choosen_number))
{
if (g_bDoingMapTouristMode)
{
CreateTimer(3.0, SetHealthOnCT);
}
else
{
PrintToChatAll("LOW POP: increased zombie knockback to X%.2f to balance gameplay", knockback_increase);
PrintToChatAll("LOW POP: increased zombie knockback to X%.2f to balance gameplay", knockback_increase);
PrintToChatAll("LOW POP: increased zombie knockback to X%.2f to balance gameplay", knockback_increase);
}
}
if (!g_bDoingMapTouristMode)
ServerCommand("zr_class_set_multiplier zombies knockback 1.0");
if (g_bDoingMapTouristMode)
{
CreateTimer(3.0, SetHealthOnCT);
}
else if (knockback_increase > 1.0)
{
PrintToChatAll("LOW POP: increased zombie knockback to X%.2f to balance gameplay", knockback_increase);
PrintToChatAll("LOW POP: increased zombie knockback to X%.2f to balance gameplay", knockback_increase);
PrintToChatAll("LOW POP: increased zombie knockback to X%.2f to balance gameplay", knockback_increase);
ServerCommand("zr_class_set_multiplier zombies knockback %.2f", knockback_increase);
}
ServerCommand("sm_iammo @all 0");
}
else
{
ServerCommand("zr_class_set_multiplier zombies knockback 1.0");
ServerCommand("sm_iammo @all 0");
}
}

View File

@ -1,19 +1,16 @@
#include <sourcemod>
#include <sdktools>
#include <zombiereloaded>
#include <cstrike>
#pragma semicolon 1
#pragma newdecls required
#define MAXNAMES 500
ArrayList g_hNames;
ArrayList g_hClanNames;
int g_iBaseLatency[MAXPLAYERS + 1];
int g_iLatency[MAXPLAYERS + 1];
int g_iAdminFakes;
int g_iFakesCount;
Database g_hDatabase;
Database g_hDatabase_hlstats;
@ -37,16 +34,14 @@ public void OnPluginStart()
{
RegAdminCmd("sm_debugfakes", Command_DebugFakes, ADMFLAG_GENERIC, "Shows the amount of fake-clients on server");
RegAdminCmd("sm_fakes", Command_Fakes, ADMFLAG_GENERIC, "Shows the fake-clients on server");
RegAdminCmd("sm_setfakes", Command_SetFakes, ADMFLAG_RCON, "Manually sets the amount of fake-clients");
int arraySize = ByteCountToCells(MAX_NAME_LENGTH);
g_hNames = CreateArray(arraySize);
g_hClanNames = CreateArray(arraySize);
g_iAdminFakes = -1;
CreateTimer(2.0, RunPopulationCheck, _, TIMER_REPEAT);
CreateTimer(GetRandomFloat(20.0, 40.0), RunPopulationCheck, _, TIMER_REPEAT);
CreateTimer(3.0, RandomizePing, _, TIMER_REPEAT);
CreateTimer(150.0, RandomizeNames, _, TIMER_REPEAT);
CreateTimer(600.0, RandomizeNames, _, TIMER_REPEAT);
HookUserMessage(GetUserMessageId("SayText2"), UserMessage_SayText2, true);
@ -58,6 +53,28 @@ public void OnPluginStart()
{
Database.Connect(SQL_OnDatabaseConnect_hlstats, "hlstatsx");
}
HookEvent("round_start", Event_roundStart, EventHookMode_Pre);
g_iFakesCount = 0;
}
public void Event_roundStart(Handle event, const char[] name, bool dontBroadcast)
{
int TimeLeft;
if (GetMapTimeLeft(TimeLeft) && TimeLeft < 0)
{
return;
}
g_iFakesCount = 0;
for(int i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
{
if (IsFakeClient(i) && !IsClientSourceTV(i))
{
g_iFakesCount++;
}
}
}
}
public void SQL_OnDatabaseConnect_hlstats(Database db, const char[] error, any data)
@ -74,7 +91,7 @@ public void SQL_OnDatabaseConnect_hlstats(Database db, const char[] error, any d
public void randomize_clantags()
{
char sQuery[512];
Format(sQuery, sizeof(sQuery), "select DISTINCT tag from unloze_stats.hlstats_Clans ORDER BY RAND() limit 500");
Format(sQuery, sizeof(sQuery), "select DISTINCT tag from unloze_stats.hlstats_Clans ORDER BY RAND() limit 1000");
g_hDatabase_hlstats.Query(SQL_OnQueryCompleted_hlstats, sQuery, DBPrio_High);
}
@ -92,7 +109,7 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
public void randomize_names()
{
char sQuery[512];
Format(sQuery, sizeof(sQuery), "select name from unloze_racetimer_css.random_names ORDER BY RAND() limit 500");
Format(sQuery, sizeof(sQuery), "select name from unloze_racetimer_css.random_names ORDER BY RAND() limit 1000");
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, DBPrio_High);
}
@ -160,34 +177,23 @@ public void OnPluginEnd()
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
g_hNames.Clear();
g_hClanNames.Clear();
if (!g_hDatabase)
for (float i = 0.0; i < g_iFakesCount;)
{
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
}
else
{
randomize_names();
}
if (!g_hDatabase_hlstats)
{
Database.Connect(SQL_OnDatabaseConnect_hlstats, "hlstatsx");
}
else
{
randomize_clantags();
i += 1.0;
CreateTimer(i, addfakes);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapEnd()
public Action addfakes(Handle timer)
{
g_iAdminFakes = -1;
CreateFake();
if (GetRandomInt(0, 10) <= 3)
{
SetFakeToTeam();
}
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -315,30 +321,6 @@ public Action Command_DebugFakes(int client, int argc)
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_SetFakes(int client, int argc)
{
if (argc < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_setfakes <amount of fakes>");
return Plugin_Handled;
}
char sArgs[16];
GetCmdArg(1, sArgs, sizeof(sArgs));
if (!StringToIntEx(sArgs, g_iAdminFakes))
{
ReplyToCommand(client, "[SM] Invalid value");
return Plugin_Handled;
}
ReplyToCommand(client, "[SM] You set the amount of Fake-Clients to %d.", g_iAdminFakes);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -427,36 +409,15 @@ public void CheckPopulation()
int iPlayers = iPlayersInTeam + iPlayersSpectate + iFakesInTeam + iFakesSpectate;
if (iPlayers >= 55)
{
if (iFakesInTeam > 0)
{
KickFakeFromTeam();
}
else if (iFakesSpectate > 1)
{
KickFakeFromSpec();
}
KickFakes();
}
else if (iPlayers > 50 && iFakesInTeam + iFakesSpectate >= 10)
{
if (iFakesInTeam >= iFakesSpectate >= 0)
{
KickFakeFromTeam();
}
else if (iFakesSpectate >= iFakesInTeam >= 1)
{
KickFakeFromSpec();
}
KickFakes();
}
else if (iPlayers >= 46 && iFakesInTeam + iFakesSpectate > 16)
{
if (iFakesInTeam >= iFakesSpectate >= 0)
{
KickFakeFromTeam();
}
else if (iFakesSpectate >= iFakesInTeam >= 1)
{
KickFakeFromSpec();
}
KickFakes();
}
else if (48 > iPlayers > 44 && iFakesSpectate + iFakesInTeam < 13)
{
@ -468,60 +429,61 @@ public void CheckPopulation()
}
}
public void ManageFakes(int iPlayersSpectate, int iPlayersInTeam, int iFakesInTeam, int iFakesSpectate)
public void KickFakes()
{
if (iPlayersSpectate + iPlayersInTeam + 6 > iFakesSpectate + iFakesInTeam)
{
CreateFake();
int max = 5;
if (iPlayersSpectate + iFakesSpectate > 16)
int fake_in_spec = 0;
int fake_in_team = 0;
int last_in_team = 0;
int last_in_spec = 0;
for(int i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
{
max = 8;
}
else if (iPlayersSpectate + iFakesSpectate < 9)
{
max = 3;
}
if (GetRandomInt(0, 10) > max)
{
SetFakeToSpectate();
}
else
{
SetFakeToTeam();
if (IsFakeClient(i) && !IsClientSourceTV(i))
{
if (GetClientTeam(i) <= CS_TEAM_SPECTATOR)
{
fake_in_spec++;
last_in_spec = i;
}
else
{
fake_in_team++;
last_in_team = i;
}
}
}
}
else
if (fake_in_spec > fake_in_team && last_in_spec != 0)
{
int max = 5;
if (iPlayersSpectate + iFakesSpectate > 16)
{
max = 8;
}
else if (iPlayersSpectate + iFakesSpectate < 9)
{
max = 3;
}
if (GetRandomInt(0, 10) > max)
{
KickFakeFromSpec();
}
else
{
KickFakeFromTeam();
}
g_iLatency[last_in_spec] = 0;
KickClient(last_in_spec, "Disconnect by user.");
}
else if (last_in_team != 0)
{
g_iLatency[last_in_team] = 0;
KickClient(last_in_team, "Disconnect by user.");
}
}
public void SetFakeToSpectate()
public void ManageFakes(int iPlayersSpectate, int iPlayersInTeam, int iFakesInTeam, int iFakesSpectate)
{
for(int i = 1; i <= MaxClients; i++)
if (iPlayersSpectate + iPlayersInTeam + 4 < iFakesSpectate + iFakesInTeam)
{
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) >= CS_TEAM_T)
KickFakes();
}
else if (iPlayersSpectate + iPlayersInTeam > iFakesSpectate + iFakesInTeam)
{
CreateFake();
int max = 3;
if (iPlayersSpectate + iFakesSpectate > 16)
{
ChangeClientTeam(i, CS_TEAM_SPECTATOR);
break;
max = 7;
}
if (GetRandomInt(0, 10) <= max)
{
SetFakeToTeam();
}
}
}
@ -539,32 +501,6 @@ public void SetFakeToTeam()
}
}
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)