Skip to content

Commit

Permalink
'Minor' fixes to freezing players
Browse files Browse the repository at this point in the history
  • Loading branch information
ipsvn committed Apr 4, 2024
1 parent 6f5317c commit 88a8e16
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
11 changes: 10 additions & 1 deletion NadeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ChaseMod.Utils.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using ChaseMod.Utils;
using CounterStrikeSharp.API;

namespace ChaseMod;
internal class NadeManager
Expand Down Expand Up @@ -49,8 +50,15 @@ private HookResult CSmokeGrenadeProjectile_CreateHook(DynamicHook hook)

var smoke = hook.GetReturn<CSmokeGrenadeProjectile>();
smoke.NextThinkTick = -1;
Utilities.SetStateChanged(smoke, "CBaseEntity", "m_nNextThinkTick");

_plugin.AddTimer(_plugin.Config.StunThrowTime, () => FreezeGrenadeExplode(smoke));
_plugin.AddTimer(_plugin.Config.StunThrowTime, () =>
{
Server.NextFrame(() =>
{
FreezeGrenadeExplode(smoke);
});
});

return HookResult.Continue;
}
Expand Down Expand Up @@ -116,4 +124,5 @@ private void FreezeGrenadeExplode(CSmokeGrenadeProjectile smoke)

smoke.Remove();
}

}
9 changes: 7 additions & 2 deletions PlayerFreezeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ChaseMod.Utils;

using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
using Microsoft.Extensions.Logging;

namespace ChaseMod;

Expand All @@ -27,9 +28,11 @@ public PlayerFreezeManager(ChaseMod chaseMod)

public void Freeze(CCSPlayerController controller, float time, bool showEffect, bool sendMessage, bool resetVelocity)
{
if (!controller.IsValid || !controller.PlayerPawn.IsValid) return;
if (!ChaseModUtils.IsRealPlayer(controller)) return;
var pawn = controller.PlayerPawn.Value!;

ChaseMod.Logger.LogInformation($"Freeze player {pawn.Index}");

var origVelocity = pawn.AbsVelocity.ToManaged();
pawn.AbsVelocity.Set(0, 0, 0);

Expand Down Expand Up @@ -74,9 +77,11 @@ public void Freeze(CCSPlayerController controller, float time, bool showEffect,

public void Unfreeze(CCSPlayerController controller, bool sendMessage)
{
if (!controller.IsValid || !controller.PlayerPawn.IsValid) return;
if (!ChaseModUtils.IsRealPlayer(controller)) return;
var pawn = controller.PlayerPawn.Value!;

ChaseMod.Logger.LogInformation($"Unfreeze player {pawn.Index}");

pawn.UnfreezePlayer();

if (_frozenPlayers.TryGetValue(controller, out var frozenState))
Expand Down
13 changes: 7 additions & 6 deletions RoundStartFreezeTimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public void Start()

foreach (var player in ChaseModUtils.GetAllRealPlayers())
{
if (!player.PlayerPawn.IsValid) continue;
var pawn = player.PlayerPawn.Value!;

if (player.Team == CsTeam.CounterTerrorist)
{
_playerFreezeManager.Freeze(player, _plugin.Config.RoundStartFreezeTime, true, false, true);
_playerFreezeManager.Freeze(player, _plugin.Config.RoundStartFreezeTime,
true, false, true);
}
}

Expand All @@ -71,12 +71,14 @@ public void Start()
_soundTimer = null;
}

if (EnableCountDownSound == true)
if (EnableCountDownSound)
{
_soundTimer = _plugin.AddTimer(1.0f, PlaySoundTimer, TimerFlags.REPEAT);
_soundTimer = _plugin.AddTimer(1.0f, PlaySoundTimer,
TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
}

_countdownTimer = _plugin.AddTimer(0.1f, CountdownTimerTick, TimerFlags.REPEAT);
_countdownTimer = _plugin.AddTimer(0.1f, CountdownTimerTick,
TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);

return HookResult.Continue;
});
Expand All @@ -96,7 +98,6 @@ private void CountdownTimerTick()
{
player.PrintToCenter(text);
}

}

private void PlaySoundTimer()
Expand Down

0 comments on commit 88a8e16

Please sign in to comment.