From 00ed042138d56668543270857e7bcaac287df335 Mon Sep 17 00:00:00 2001 From: TtroubleTT Date: Thu, 1 Aug 2024 15:30:43 -0700 Subject: [PATCH 1/3] Fix custom role classes giving custom ammmo when they are not suppose to --- .../API/Features/CustomRole.cs | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index 51e4ac008..355dbbb60 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -539,6 +539,21 @@ public virtual void AddRole(Player player) } }); + if (Ammo.Count > 0) + { + Timing.CallDelayed( + 0.5f, + () => + { + Log.Debug($"{Name}: Adding Ammo to {player.Nickname} inventory."); + foreach (AmmoType type in Enum.GetValues(typeof(AmmoType))) + { + if (type != AmmoType.None) + player.SetAmmo(type, Ammo.ContainsKey(type) ? Ammo[type] == ushort.MaxValue ? InventoryLimits.GetAmmoLimit(type.GetItemType(), player.ReferenceHub) : Ammo[type] : (ushort)0); + } + }); + } + Log.Debug($"{Name}: Setting health values."); player.Health = MaxHealth; player.MaxHealth = MaxHealth; @@ -910,25 +925,6 @@ private void OnInternalChangingRole(ChangingRoleEventArgs ev) { RemoveRole(ev.Player); } - else if (Check(ev.Player)) - { - Log.Debug($"{Name}: Checking ammo stuff {Ammo.Count}"); - if (Ammo.Count > 0) - { - Log.Debug($"{Name}: Clearing ammo"); - ev.Ammo.Clear(); - Timing.CallDelayed( - 0.5f, - () => - { - foreach (AmmoType type in Enum.GetValues(typeof(AmmoType))) - { - if (type != AmmoType.None) - ev.Player.SetAmmo(type, Ammo.ContainsKey(type) ? Ammo[type] == ushort.MaxValue ? InventoryLimits.GetAmmoLimit(type.GetItemType(), ev.Player.ReferenceHub) : Ammo[type] : (ushort)0); - } - }); - } - } } private void OnSpawningRagdoll(SpawningRagdollEventArgs ev) From 43b6ea9934b8db2dfbb4e2d6f8a4b300d2d4fd8d Mon Sep 17 00:00:00 2001 From: TtroubleTT Date: Fri, 2 Aug 2024 22:04:21 -0700 Subject: [PATCH 2/3] change to using EnumUtils --- EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index 355dbbb60..ece179511 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -546,7 +546,7 @@ public virtual void AddRole(Player player) () => { Log.Debug($"{Name}: Adding Ammo to {player.Nickname} inventory."); - foreach (AmmoType type in Enum.GetValues(typeof(AmmoType))) + foreach (AmmoType type in EnumUtils.Values) { if (type != AmmoType.None) player.SetAmmo(type, Ammo.ContainsKey(type) ? Ammo[type] == ushort.MaxValue ? InventoryLimits.GetAmmoLimit(type.GetItemType(), player.ReferenceHub) : Ammo[type] : (ushort)0); From c0bf400504c3b4e6789bbbd408b4ccd3b260d3c1 Mon Sep 17 00:00:00 2001 From: TtroubleTT Date: Tue, 6 Aug 2024 02:41:52 -0700 Subject: [PATCH 3/3] Moved Ammo additions into Inventory call delayed --- EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index ece179511..61f88ec2c 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -537,13 +537,8 @@ public virtual void AddRole(Player player) Log.Debug($"{Name}: Adding {itemName} to inventory."); TryAddItem(player, itemName); } - }); - if (Ammo.Count > 0) - { - Timing.CallDelayed( - 0.5f, - () => + if (Ammo.Count > 0) { Log.Debug($"{Name}: Adding Ammo to {player.Nickname} inventory."); foreach (AmmoType type in EnumUtils.Values) @@ -551,8 +546,8 @@ public virtual void AddRole(Player player) if (type != AmmoType.None) player.SetAmmo(type, Ammo.ContainsKey(type) ? Ammo[type] == ushort.MaxValue ? InventoryLimits.GetAmmoLimit(type.GetItemType(), player.ReferenceHub) : Ammo[type] : (ushort)0); } - }); - } + } + }); Log.Debug($"{Name}: Setting health values."); player.Health = MaxHealth;