Skip to content

Commit

Permalink
0.3 version
Browse files Browse the repository at this point in the history
Fixes map not being changed
  • Loading branch information
Cruze03 authored Dec 29, 2023
1 parent 7fd8f98 commit ed25a02
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions WorkshopDefaultMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace WorkshopDefaultMap;
public class WorkshopDefaultMap : BasePlugin
{
public override string ModuleName => "Workshop Collection Default Map";
public override string ModuleVersion => "0.2";
public override string ModuleVersion => "0.3";
public override string ModuleAuthor => "Cruze";
public override string ModuleDescription => "Sets default map after server restart";

Expand All @@ -17,6 +17,8 @@ public class WorkshopDefaultMap : BasePlugin

private bool g_bChangeMap = true;

public CounterStrikeSharp.API.Modules.Timers.Timer? g_Timer = null;

public override void Load(bool hotReload)
{
base.Load(hotReload);
Expand All @@ -33,21 +35,29 @@ public override void Load(bool hotReload)
Log($"MapName found: {MapName}");

RegisterListener<Listeners.OnMapStart>(OnMapStart);

if(hotReload)
{
OnMapStart(Server.MapName);
}
}

private void OnMapStart(string mapName)
{
if (!g_bChangeMap || string.IsNullOrEmpty(MapName)) return;

AddTimer(7.0f, () => ChangeMap(), TimerFlags.STOP_ON_MAPCHANGE);
if(g_Timer != null)
g_Timer.Kill();

g_Timer = AddTimer(7.0f, () => ChangeMap());
Log($"Changing map to {MapName}...");
}

private void ChangeMap()
{
g_Timer = null;
if (!g_bChangeMap || string.IsNullOrEmpty(MapName))
{
LogError($"[ChangeMap] Error. {g_bChangeMap} & \"{MapName}\"");
return;
}

Expand Down

0 comments on commit ed25a02

Please sign in to comment.