From cd1a6a4bb93447a66e064885e44cbeeb7dcd0468 Mon Sep 17 00:00:00 2001 From: Sachin <31343375+Cruze03@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:09:59 +0530 Subject: [PATCH] Add files via upload --- WorkshopDefaultMap.cs | 59 +++++++++++++++++++++++++++++++++++++++ WorkshopDefaultMap.csproj | 19 +++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 WorkshopDefaultMap.cs create mode 100644 WorkshopDefaultMap.csproj diff --git a/WorkshopDefaultMap.cs b/WorkshopDefaultMap.cs new file mode 100644 index 0000000..fe90c10 --- /dev/null +++ b/WorkshopDefaultMap.cs @@ -0,0 +1,59 @@ +namespace WorkshopDefaultMap; + +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; + +public class WorkshopDefaultMap : BasePlugin +{ + public override string ModuleName => "Workshop Collection Default Map"; + public override string ModuleVersion => "0.1"; + public override string ModuleAuthor => "Cruze"; + public override string ModuleDescription => "Sets default map after server restart"; + + private string FilePath => Path.Join(ModuleDirectory, "WorkshopDefaultMap.txt"); + + private string MapName = ""; + + private bool g_bChangeMap; + + public override void Load(bool hotReload) + { + base.Load(hotReload); + + MapName = File.ReadAllText(FilePath); + + if(string.IsNullOrEmpty(MapName)) + { + Log("WorkshopDefaultMap.txt is blank. Plugin will not work as intended."); + } + + g_bChangeMap = true; + + RegisterListener(OnMapStart); + } + + private void OnMapStart(string mapName) + { + if (!g_bChangeMap || string.IsNullOrEmpty(MapName)) return; + + base.AddTimer(2.0f, Timer_OnMapStart); + } + + private void Timer_OnMapStart() + { + if (!g_bChangeMap) return; + + Server.ExecuteCommand($"ds_workshop_changelevel {MapName}"); + NativeAPI.IssueServerCommand($"ds_workshop_changelevel {MapName}"); + + g_bChangeMap = false; + } + + private static void Log(string message) + { + Console.BackgroundColor = ConsoleColor.DarkGray; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(message); + Console.ResetColor(); + } +} \ No newline at end of file diff --git a/WorkshopDefaultMap.csproj b/WorkshopDefaultMap.csproj new file mode 100644 index 0000000..3583072 --- /dev/null +++ b/WorkshopDefaultMap.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + enable + enable + + + + + + + CounterStrikeSharp.API.dll + + + + + +