[+] Improved and simplified GetWeaponNameByHash Function in WeaponManager

This commit is contained in:
Lukas Moungos
2019-12-13 19:15:09 +01:00
parent 50fd71eb15
commit 85b052b729
2 changed files with 12 additions and 18 deletions

View File

@@ -60,7 +60,7 @@ namespace ReallifeGamemode.Server.Events
//string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + NAPI.Player.GetPlayerCurrentWeapon(killer) + ")"; //string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + NAPI.Player.GetPlayerCurrentWeapon(killer) + ")";
string weaponHash = NAPI.Player.GetPlayerCurrentWeapon(killer).ToString(); string weaponHash = NAPI.Player.GetPlayerCurrentWeapon(killer).ToString();
ChatService.Broadcast("test: " + weaponHash); 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); ChatService.BroadcastAdmin(message, AdminLevel.ADMIN);
} }
} }

View File

@@ -103,10 +103,7 @@ namespace ReallifeGamemode.Server.Managers
"fireextinguisher" "fireextinguisher"
}; };
public static Dictionary<string, string> WeaponHashDictionary = new Dictionary<string, string>
{
{ "2441047180", "NavyRevolver" }
};
public static bool IsValidHash(uint hash) public static bool IsValidHash(uint hash)
{ {
@@ -115,29 +112,26 @@ namespace ReallifeGamemode.Server.Managers
if ((uint)vh == hash) return true; if ((uint)vh == hash) return true;
} }
/*
foreach (string mod in _modWeapons) foreach (string mod in _modWeapons)
{ {
if (NAPI.Util.GetHashKey($"weapon_{mod}") == hash) return true; if (NAPI.Util.GetHashKey($"weapon_{mod}") == hash) return true;
} }
*/
Dictionary<string, string>.ValueCollection values = WeaponHashDictionary.Values;
foreach (string mod in values)
{
if (NAPI.Util.GetHashKey($"weapon_{mod}") == hash) return true;
}
return false; 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";
} }
} }
} }