From 85b052b729029cbc632b8ffeb22bb0704d4ae7c8 Mon Sep 17 00:00:00 2001 From: Lukas Moungos Date: Fri, 13 Dec 2019 19:15:09 +0100 Subject: [PATCH] [+] Improved and simplified GetWeaponNameByHash Function in WeaponManager --- ReallifeGamemode.Server/Events/Death.cs | 2 +- .../Managers/WeaponManager.cs | 28 ++++++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index c139df91..1f9afb7a 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -60,7 +60,7 @@ namespace ReallifeGamemode.Server.Events //string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + NAPI.Player.GetPlayerCurrentWeapon(killer) + ")"; string weaponHash = NAPI.Player.GetPlayerCurrentWeapon(killer).ToString(); ChatService.Broadcast("test: " + weaponHash); - string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + Managers.WeaponManager.GetWeaponNameByHash(weaponHash) + ")"; + string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + Managers.WeaponManager.GetWeaponNameByHash((uint)killer.Weapons.GetHashCode()) + ")"; ChatService.BroadcastAdmin(message, AdminLevel.ADMIN); } } diff --git a/ReallifeGamemode.Server/Managers/WeaponManager.cs b/ReallifeGamemode.Server/Managers/WeaponManager.cs index e441d830..7a97cc73 100644 --- a/ReallifeGamemode.Server/Managers/WeaponManager.cs +++ b/ReallifeGamemode.Server/Managers/WeaponManager.cs @@ -103,10 +103,7 @@ namespace ReallifeGamemode.Server.Managers "fireextinguisher" }; - public static Dictionary WeaponHashDictionary = new Dictionary - { - { "2441047180", "NavyRevolver" } - }; + public static bool IsValidHash(uint hash) { @@ -115,29 +112,26 @@ namespace ReallifeGamemode.Server.Managers if ((uint)vh == hash) return true; } - /* foreach (string mod in _modWeapons) { if (NAPI.Util.GetHashKey($"weapon_{mod}") == hash) return true; } - */ - - Dictionary.ValueCollection values = WeaponHashDictionary.Values; - foreach (string mod in values) - { - if (NAPI.Util.GetHashKey($"weapon_{mod}") == hash) return true; - } - return false; } - public static String GetWeaponNameByHash(String hash) + public static String GetWeaponNameByHash(uint hash) { - if (WeaponHashDictionary.ContainsKey(hash)) + if (!IsValidHash(hash)) + return "unbekannt"; + + foreach (var w in _modWeapons) { - return WeaponHashDictionary[hash]; + if(NAPI.Util.GetHashKey(w) == hash) + { + return w; + } } - return null; + return "unbekannt"; } } }