From c920a76681eede1ab8db54078a5dea47c6ec39a3 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Sun, 18 Sep 2022 17:42:20 +0200 Subject: [PATCH] Create manage_bots_fill --- small_scripts/README.md | 7 +++ small_scripts/manage_bots_fill.gsc | 79 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 small_scripts/manage_bots_fill.gsc diff --git a/small_scripts/README.md b/small_scripts/README.md index 2ffe30b..6bc3ce9 100644 --- a/small_scripts/README.md +++ b/small_scripts/README.md @@ -57,6 +57,13 @@ This checks for bots kills and deaths every 30 seconds. If they didn't do any ki Obviously a better way to do this would be checking for their positions or removing bad spawns on the map or creating waypoints for the map. This is just a quick temporary solution that works for me. +## manage_bots_fill.gsc + +Simple script that changes the Bot Warfare `bots_manage_fill` dvar dynamically to avoid using resource for an empty server. +Whenever a player connects or disconnects the script checks the amount of human players and the value of `bots_manage_fill` and sets it accordingly. +If the first player joins, it sets the dvar to the value you configured for that specific server (set in `InitServersDvar()` with the server port). +If the last player leaves it sets back the dvar to 0 so that no bots will be playing, saving some resources on that server. + ## remove_heavy_weapon_slow.gsc Set back your speed scale to default whenever you have an heavy weapon equipped. diff --git a/small_scripts/manage_bots_fill.gsc b/small_scripts/manage_bots_fill.gsc new file mode 100644 index 0000000..9497396 --- /dev/null +++ b/small_scripts/manage_bots_fill.gsc @@ -0,0 +1,79 @@ +#include maps\mp\bots\_bot_utility; + +Init() +{ + InitManageBotsFill(); +} + +InitManageBotsFill() +{ + InitServersDvar(); + + SetDvar("bots_manage_fill_kick", 1); + + level thread OnPlayerConnect(); +} + +OnPlayerConnect() +{ + for (;;) + { + level waittill("connected", player); + + if (!player IsBot()) + { + TryUpdateBotsManageFill(); + + player thread OnPlayerDisconnect(); + } + } +} + +OnPlayerDisconnect() +{ + self waittill("disconnect"); + + TryUpdateBotsManageFill(); +} + +InitServersDvar() +{ + level.manage_bots_fill = []; + + level.manage_bots_fill["27017"] = "12"; +} + +TryUpdateBotsManageFill() +{ + wait 1; + + if (HasHumanPlayers()) + { + if (GetDvar("bots_manage_fill") != level.manage_bots_fill[GetDvar("net_port")]) + { + SetDvar("bots_manage_fill", level.manage_bots_fill[GetDvar("net_port")]); + } + } + else + { + SetDvar("bots_manage_fill", 0); + } +} + +IsBot() +{ + return IsDefined(self.pers["isBot"]) && self.pers["isBot"]; +} + +HasHumanPlayers() +{ + foreach (player in level.players) + { + if (!player IsBot()) + { + return true; + } + } + + return false; +} \ No newline at end of file