Skip to content

Commit 00ed042

Browse files
committed
Fix custom role classes giving custom ammmo when they are not suppose to
1 parent c9654ee commit 00ed042

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@ public virtual void AddRole(Player player)
539539
}
540540
});
541541

542+
if (Ammo.Count > 0)
543+
{
544+
Timing.CallDelayed(
545+
0.5f,
546+
() =>
547+
{
548+
Log.Debug($"{Name}: Adding Ammo to {player.Nickname} inventory.");
549+
foreach (AmmoType type in Enum.GetValues(typeof(AmmoType)))
550+
{
551+
if (type != AmmoType.None)
552+
player.SetAmmo(type, Ammo.ContainsKey(type) ? Ammo[type] == ushort.MaxValue ? InventoryLimits.GetAmmoLimit(type.GetItemType(), player.ReferenceHub) : Ammo[type] : (ushort)0);
553+
}
554+
});
555+
}
556+
542557
Log.Debug($"{Name}: Setting health values.");
543558
player.Health = MaxHealth;
544559
player.MaxHealth = MaxHealth;
@@ -910,25 +925,6 @@ private void OnInternalChangingRole(ChangingRoleEventArgs ev)
910925
{
911926
RemoveRole(ev.Player);
912927
}
913-
else if (Check(ev.Player))
914-
{
915-
Log.Debug($"{Name}: Checking ammo stuff {Ammo.Count}");
916-
if (Ammo.Count > 0)
917-
{
918-
Log.Debug($"{Name}: Clearing ammo");
919-
ev.Ammo.Clear();
920-
Timing.CallDelayed(
921-
0.5f,
922-
() =>
923-
{
924-
foreach (AmmoType type in Enum.GetValues(typeof(AmmoType)))
925-
{
926-
if (type != AmmoType.None)
927-
ev.Player.SetAmmo(type, Ammo.ContainsKey(type) ? Ammo[type] == ushort.MaxValue ? InventoryLimits.GetAmmoLimit(type.GetItemType(), ev.Player.ReferenceHub) : Ammo[type] : (ushort)0);
928-
}
929-
});
930-
}
931-
}
932928
}
933929

934930
private void OnSpawningRagdoll(SpawningRagdollEventArgs ev)

0 commit comments

Comments
 (0)