From 5a5b120674d5809e67e1ee69f003c055d3505c7a Mon Sep 17 00:00:00 2001 From: Nereziel Date: Tue, 14 Nov 2023 19:54:22 +0100 Subject: [PATCH] change knife give handling --- WeaponPaints.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/WeaponPaints.cs b/WeaponPaints.cs index e2f5b96e..f6868282 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -140,7 +140,18 @@ public class WeaponPaints : BasePlugin, IPluginConfig player.GiveNamedItem("weapon_knife"); return HookResult.Continue; } - if (!PlayerHasKnife(player)) player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]); + + if (!PlayerHasKnife(player)) + { + if (g_playersKife.ContainsKey((int)player.EntityIndex!.Value.Value)) + { + player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]); + } + else + { + player.GiveNamedItem("weapon_knife"); + } + } return HookResult.Continue; } @@ -192,6 +203,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig public void RemoveKnifeFromPlayer(CCSPlayerController player) { if (!player.PawnIsAlive) return; + if (!g_playersKife.ContainsKey((int)player.EntityIndex!.Value.Value)) return; var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons; foreach (var weapon in weapons) { @@ -330,10 +342,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig { g_playersKife[playerIndex] = knife; } - else - { - g_playersKife[playerIndex] = "weapon_knife"; - } //Log($"{player.PlayerName} has this knife -> {g_playersKife[playerIndex]}"); } catch (Exception e) @@ -357,7 +365,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig return; } } - private static void Log(string message) { Console.BackgroundColor = ConsoleColor.DarkGray;