-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |