From b7289dd1e807d77902b8fb67258276332c00c2b3 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:23:23 +0200 Subject: [PATCH] Update Events.cs - Music kits fix --- Events.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Events.cs b/Events.cs index 348fed38..22bdfefd 100644 --- a/Events.cs +++ b/Events.cs @@ -9,6 +9,8 @@ namespace WeaponPaints { public partial class WeaponPaints { + private bool _mvpPlayed; + [GameEventHandler] public HookResult OnClientFullConnect(EventPlayerConnectFull @event, GameEventInfo info) { @@ -148,6 +150,39 @@ private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { _gBCommandsAllowed = true; + _mvpPlayed = false; + return HookResult.Continue; + } + + private HookResult OnRoundMvp(EventRoundMvp @event, GameEventInfo info) + { + if (_mvpPlayed) + return HookResult.Continue; + + var player = @event.Userid; + + if (player == null || !player.IsValid || player.IsBot) + return HookResult.Continue; + + if (!(GPlayersMusic.TryGetValue(player.Slot, out var musicInfo) + && musicInfo.TryGetValue(player.Team, out var musicId) + && musicId != 0)) + return HookResult.Continue; + + @event.Musickitid = musicId; + @event.Nomusic = 0; + info.DontBroadcast = true; + + var newEvent = new EventRoundMvp(true) + { + Userid = player, + Musickitid = musicId, + Nomusic = 0, + }; + + _mvpPlayed = true; + + newEvent.FireEvent(false); return HookResult.Continue; } @@ -289,6 +324,7 @@ private void RegisterListeners() RegisterEventHandler(OnPlayerSpawn); RegisterEventHandler(OnRoundStart); RegisterEventHandler(OnRoundEnd); + RegisterEventHandler(OnRoundMvp); RegisterListener(OnEntityCreated); RegisterEventHandler(OnPlayerDeath);