Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom role classes giving custom ammo when they are not suppose to #24

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading