Skip to content

Commit

Permalink
Fix custom role classes giving custom ammo when they are not suppose …
Browse files Browse the repository at this point in the history
…to (#24)

* Fix custom role classes giving custom ammmo when they are not suppose to

* change to using EnumUtils

* Moved Ammo additions into Inventory call delayed
  • Loading branch information
TtroubleTT authored Aug 7, 2024
1 parent 26d1fcc commit 03d6bd7
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ public virtual void AddRole(Player player)
Log.Debug($"{Name}: Adding {itemName} to inventory.");
TryAddItem(player, itemName);
}

if (Ammo.Count > 0)
{
Log.Debug($"{Name}: Adding Ammo to {player.Nickname} inventory.");
foreach (AmmoType type in EnumUtils<AmmoType>.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);
}
}
});

Log.Debug($"{Name}: Setting health values.");
Expand Down Expand Up @@ -910,25 +920,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)
Expand Down

0 comments on commit 03d6bd7

Please sign in to comment.