diff --git a/EXILED/Exiled.CustomItems/API/Features/CustomWeapon.cs b/EXILED/Exiled.CustomItems/API/Features/CustomWeapon.cs
index e775ee3e9f..ac8930dee9 100644
--- a/EXILED/Exiled.CustomItems/API/Features/CustomWeapon.cs
+++ b/EXILED/Exiled.CustomItems/API/Features/CustomWeapon.cs
@@ -16,6 +16,7 @@ namespace Exiled.CustomItems.API.Features
using Exiled.API.Features.DamageHandlers;
using Exiled.API.Features.Items;
using Exiled.API.Features.Pickups;
+ using Exiled.Events.EventArgs.Item;
using Exiled.Events.EventArgs.Player;
using InventorySystem;
using InventorySystem.Items.Firearms.Attachments;
@@ -151,6 +152,7 @@ protected override void SubscribeEvents()
Exiled.Events.Handlers.Player.Shooting += OnInternalShooting;
Exiled.Events.Handlers.Player.Shot += OnInternalShot;
Exiled.Events.Handlers.Player.Hurting += OnInternalHurting;
+ Exiled.Events.Handlers.Item.ChangingAttachments += OnInternalChangingAttachment;
base.SubscribeEvents();
}
@@ -163,6 +165,7 @@ protected override void UnsubscribeEvents()
Exiled.Events.Handlers.Player.Shooting -= OnInternalShooting;
Exiled.Events.Handlers.Player.Shot -= OnInternalShot;
Exiled.Events.Handlers.Player.Hurting -= OnInternalHurting;
+ Exiled.Events.Handlers.Item.ChangingAttachments -= OnInternalChangingAttachment;
base.UnsubscribeEvents();
}
@@ -209,6 +212,14 @@ protected virtual void OnHurting(HurtingEventArgs ev)
ev.Amount = Damage;
}
+ ///
+ /// Handles attachment changing for custom weapons.
+ ///
+ /// .
+ protected virtual void OnChangingAttachment(ChangingAttachmentsEventArgs ev)
+ {
+ }
+
private void OnInternalReloading(ReloadingWeaponEventArgs ev)
{
if (!Check(ev.Player.CurrentItem))
@@ -321,5 +332,13 @@ private void OnInternalHurting(HurtingEventArgs ev)
OnHurting(ev);
}
+
+ private void OnInternalChangingAttachment(ChangingAttachmentsEventArgs ev)
+ {
+ if (!Check(ev.Player.CurrentItem))
+ return;
+
+ OnChangingAttachment(ev);
+ }
}
}
\ No newline at end of file
diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
index 60d3f44d60..df2920e50f 100644
--- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
+++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
@@ -17,6 +17,7 @@ namespace Exiled.CustomRoles.API.Features
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.Attributes;
+ using Exiled.API.Features.Items;
using Exiled.API.Features.Pools;
using Exiled.API.Features.Spawn;
using Exiled.API.Interfaces;
@@ -535,7 +536,14 @@ public virtual void AddRole(Player player)
foreach (string itemName in Inventory)
{
Log.Debug($"{Name}: Adding {itemName} to inventory.");
- TryAddItem(player, itemName);
+ if (TryAddItem(player, itemName) && CustomItem.TryGet(itemName, out CustomItem? customItem) && customItem is CustomWeapon customWeapon)
+ {
+ if (player.CurrentItem is Firearm firearm && !customWeapon.Attachments.IsEmpty())
+ {
+ firearm.AddAttachment(customWeapon.Attachments);
+ Log.Debug($"{Name}: Applied attachments to {itemName}.");
+ }
+ }
}
if (Ammo.Count > 0)