Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruze03 authored Nov 17, 2023
1 parent 2076c6f commit cd1a6a4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
59 changes: 59 additions & 0 deletions WorkshopDefaultMap.cs
Original file line number Diff line number Diff line change
@@ -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<Listeners.OnMapStart>(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();
}
}
19 changes: 19 additions & 0 deletions WorkshopDefaultMap.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>

<Reference Include="CounterStrikeSharp.API">

<HintPath>CounterStrikeSharp.API.dll</HintPath>

</Reference>

</ItemGroup>

</Project>

0 comments on commit cd1a6a4

Please sign in to comment.