diff --git a/src/RollTheDice+DiceBigTaserBattery.cs b/src/RollTheDice+DiceBigTaserBattery.cs index 02cb201..70656eb 100644 --- a/src/RollTheDice+DiceBigTaserBattery.cs +++ b/src/RollTheDice+DiceBigTaserBattery.cs @@ -8,6 +8,11 @@ public partial class RollTheDice : BasePlugin private Dictionary DiceBigTaserBattery(CCSPlayerController player, CCSPlayerPawn playerPawn) { + // create listener if not exists + if (_playersWithBigTaserBattery.Count() == 0) + { + RegisterEventHandler(EventDiceBigTaserBatteryOnWeaponFire); + } int battery = _random.Next(2, 10); _playersWithBigTaserBattery.Add(player, battery); player.GiveNamedItem("weapon_taser"); @@ -20,11 +25,6 @@ private Dictionary DiceBigTaserBattery(CCSPlayerController playe }; } - private void DiceBigTaserBatteryLoad() - { - RegisterEventHandler(EventDiceBigTaserBatteryOnWeaponFire); - } - private void DiceBigTaserBatteryUnload() { DiceBigTaserBatteryReset(); @@ -32,6 +32,7 @@ private void DiceBigTaserBatteryUnload() private void DiceBigTaserBatteryReset() { + DeregisterEventHandler(EventDiceBigTaserBatteryOnWeaponFire); _playersWithBigTaserBattery.Clear(); } diff --git a/src/RollTheDice+DiceFastBombAction.cs b/src/RollTheDice+DiceFastBombAction.cs index 959ed23..408f473 100644 --- a/src/RollTheDice+DiceFastBombAction.cs +++ b/src/RollTheDice+DiceFastBombAction.cs @@ -11,6 +11,12 @@ public partial class RollTheDice : BasePlugin private Dictionary DiceFastBombAction(CCSPlayerController player, CCSPlayerPawn playerPawn) { + // create listener if not exists + if (_playersCanInstantDefuse.Count() == 0 && _playersCanInstantPlant.Count() == 0) + { + RegisterEventHandler(DiceFastBombActionEventBeginDefuse); + RegisterEventHandler(DiceFastBombActionEventBeginPlant); + } if (playerPawn.TeamNum == (int)CsTeam.Terrorist) { _playersCanInstantPlant.Add(player); @@ -41,12 +47,6 @@ private Dictionary DiceFastBombAction(CCSPlayerController player } } - private void DiceFastBombActionLoad() - { - RegisterEventHandler(DiceFastBombActionEventBeginDefuse); - RegisterEventHandler(DiceFastBombActionEventBeginPlant); - } - private void DiceFastBombActionUnload() { DiceFastBombActionReset(); @@ -54,6 +54,8 @@ private void DiceFastBombActionUnload() private void DiceFastBombActionReset() { + DeregisterEventHandler(DiceFastBombActionEventBeginDefuse); + DeregisterEventHandler(DiceFastBombActionEventBeginPlant); _playersCanInstantDefuse.Clear(); _playersCanInstantPlant.Clear(); } diff --git a/src/RollTheDice+DiceIncreaseSpeed.cs b/src/RollTheDice+DiceIncreaseSpeed.cs index c79d94f..caeec8f 100644 --- a/src/RollTheDice+DiceIncreaseSpeed.cs +++ b/src/RollTheDice+DiceIncreaseSpeed.cs @@ -10,6 +10,11 @@ public partial class RollTheDice : BasePlugin private Dictionary DiceIncreaseSpeed(CCSPlayerController player, CCSPlayerPawn playerPawn) { + // create listener if not exists + if (_playersWithIncreasedSpeed.Count() == 0) + { + RegisterEventHandler(EventDiceIncreaseSpeedOnPlayerHurt); + } _playersWithIncreasedSpeed.Add(player); var speedIncrease = _random.NextDouble() * (2.0 - 1.5) + 1.5; playerPawn.VelocityModifier *= (float)speedIncrease; @@ -25,11 +30,6 @@ private Dictionary DiceIncreaseSpeed(CCSPlayerController player, }; } - private void DiceIncreaseSpeedLoad() - { - RegisterEventHandler(EventDiceIncreaseSpeedOnPlayerHurt); - } - private void DiceIncreaseSpeedUnload() { DiceIncreaseSpeedReset(); @@ -37,6 +37,7 @@ private void DiceIncreaseSpeedUnload() private void DiceIncreaseSpeedReset() { + DeregisterEventHandler(EventDiceIncreaseSpeedOnPlayerHurt); // iterate through all players foreach (var player in _playersWithIncreasedSpeed) {