From c477294afe1f81a62323227105bb74d42354173c Mon Sep 17 00:00:00 2001 From: Oldcustard <147gusto@gmail.com> Date: Thu, 2 Mar 2023 00:26:57 +1100 Subject: [PATCH] updates --- .gitignore | 1 + configs/config_loader.cfg | 17 ++++++ scripting/config_loader.sp | 118 +++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 .gitignore create mode 100644 configs/config_loader.cfg create mode 100644 scripting/config_loader.sp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0804053 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.smx \ No newline at end of file diff --git a/configs/config_loader.cfg b/configs/config_loader.cfg new file mode 100644 index 0000000..773cdd4 --- /dev/null +++ b/configs/config_loader.cfg @@ -0,0 +1,17 @@ +"Map_Configs" +{ + "cp" + { + "cp_steel_" "ozf-hl-stopwatch" + "cp_" "ozf-6s-5cp" + } + "pl" + { + "pl_" "ozf-hl-stopwatch" + } + "koth" + { + "koth_product_" "" + "koth_" "ozf-hl-koth" + } +} \ No newline at end of file diff --git a/scripting/config_loader.sp b/scripting/config_loader.sp new file mode 100644 index 0000000..3e81f62 --- /dev/null +++ b/scripting/config_loader.sp @@ -0,0 +1,118 @@ +#include +#include +#include +// ^ tf2_stocks.inc itself includes sdktools.inc and tf2.inc + +#pragma semicolon 1 +#pragma newdecls required + +#define PLUGIN_VERSION "0.1" + +public Plugin myinfo = +{ + name = "Config Reminder", + author = "Rhizome", + description = "Hassles users until they exec", + version = PLUGIN_VERSION, + url = "https://rhizome.tf" +}; + +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + // No need for the old GetGameFolderName setup. + EngineVersion g_engineversion = GetEngineVersion(); + if (g_engineversion != Engine_TF2) + { + SetFailState("This plugin was made for use with Team Fortress 2 only."); + } +} + +public void OnPluginStart() +{ + /** + * @note For the love of god, please stop using FCVAR_PLUGIN. + * Console.inc even explains this above the entry for the FCVAR_PLUGIN define. + * "No logic using this flag ever existed in a released game. It only ever appeared in the first hl2sdk." + */ + CreateConVar("sm_pluginnamehere_version", PLUGIN_VERSION, "Standard plugin version ConVar. Please don't change me!", FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD); +} + +public void OnMapStart() +{ + /** + * @note Precache your models, sounds, etc. here! + * Not in OnConfigsExecuted! Doing so leads to issues. + */ + CreateTimer(15.0, PostReminder, 0, TIMER_REPEAT); + HookEvent("teamplay_restart_round", BlockStart, EventHookMode_Pre); + + char config_name[64]; + LoadConfig(config_name, sizeof(config_name)); +} + +Action PostReminder(Handle timer, any data) +{ + CPrintToChatAll("{red}No config is applied! Ensure config is applied before starting."); + return Plugin_Handled; +} + +Action BlockStart(Event event, const char[] name, bool dontBroadcast) +{ + ServerCommand("mp_tournament_restart"); + CPrintToChatAll("{red}Bad rollout! {default}(Did you forget to exec?)"); + return Plugin_Handled; +} + +bool LoadConfig(char[] config_name, int maxlength) +{ + char current_map[64]; + GetCurrentMap(current_map, sizeof(current_map)); + + char map_type[8]; + if (SplitString(current_map, "_", map_type, sizeof(map_type)) == -1) + { + PrintToServer("[AUTOCONFIG] Couldn't find map prefix'"); + return false; + } + + KeyValues map_configs = CreateKeyValues("Map_Configs"); + + char config_file[256]; + BuildPath(Path_SM, config_file, sizeof(config_file), "configs/config_loader.cfg"); + map_configs.ImportFromFile(config_file); + + if (!map_configs.JumpToKey(map_type)) + { + PrintToServer("[AUTOCONFIG] Couldn't find table for '%s' maps'", map_type); + return false; + } + + + if (!map_configs.GotoFirstSubKey(false)) + { + PrintToServer("[AUTOCONFIG] No maps listed for '%s' maps'", map_type); + return false; + } + + + while (true) + { + char current_key[64]; + map_configs.GetSectionName(current_key, sizeof(current_key)); + PrintToServer(current_key); + + if (StrContains(current_map, current_key, false) != -1) + { + map_configs.GetString(current_key, config_name, maxlength); + PrintToServer("[AUTOCONFIG] Found applicable config: %s", config_name); + return true; + } + + if (!map_configs.GotoNextKey(false)) + { + PrintToServer("[AUTOCONFIG] No match found for %s", current_map); + return false; + } + } + +} \ No newline at end of file