Skip to content

Commit

Permalink
fix: clear zone.Data on round start
Browse files Browse the repository at this point in the history
fix: cache gameRules
  • Loading branch information
oscar-wos committed Aug 7, 2024
1 parent a0d0406 commit 968f806
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/AntiRush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public override void Load(bool isReload)

Server.NextFrame(() =>
{
_gameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
foreach (var controller in Utilities.GetPlayers())
_playerData[controller] = new PlayerData();
Expand Down
7 changes: 5 additions & 2 deletions src/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
_roundStart = Server.CurrentTime;
_bombPlanted = false;

var gameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
_warmup = gameRules.WarmupPeriod;
_gameRules ??= Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
_warmup = _gameRules.WarmupPeriod;

if (!Config.DrawZones)
return HookResult.Continue;

foreach (var zone in _zones)
{
zone.Data = [];
zone.Draw();
}

return HookResult.Continue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AntiRush;
public partial class AntiRush
{
public override string ModuleName => "AntiRush";
public override string ModuleVersion => "1.0.5";
public override string ModuleVersion => "1.0.6";
public override string ModuleAuthor => "https://github.com/oscar-wos/AntiRush";
public AntiRushConfig Config { get; set; } = new();
public Menu.Menu Menu { get; } = new();
Expand All @@ -20,4 +20,5 @@ public partial class AntiRush
private bool _bombPlanted;
private bool _warmup;
private float[] _countdown = [];
private CCSGameRules? _gameRules;
}
2 changes: 1 addition & 1 deletion src/Zone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Zone(string name, ZoneType type, float delay, int damage, CsTeam[]
public CsTeam[] Teams { get; init; } = teams;
public Vector MinPoint { get; init; } = minPoint;
public Vector MaxPoint { get; init; } = maxPoint;
public Dictionary<CCSPlayerController, ZoneData> Data { get; } = [];
public Dictionary<CCSPlayerController, ZoneData> Data { get; set; } = [];
public CBeam[] Beams { get; } = [];

public bool IsInZone(Vector point)
Expand Down

0 comments on commit 968f806

Please sign in to comment.