diff --git a/Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs b/Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs new file mode 100644 index 0000000000..49118d9799 --- /dev/null +++ b/Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs @@ -0,0 +1,15 @@ +using Content.Shared.Whitelist; +using Robust.Shared.Prototypes; +using Robust.Shared.GameStates; + +namespace Content.Shared.Sound.Components; + +/// +/// Whenever this item is used upon by an entity, with a tag or component within a whitelist, in the hand of a user, play a sound +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class EmitSoundOnInteractUsingComponent : BaseEmitSoundComponent +{ + [DataField(required: true)] + public EntityWhitelist Whitelist = new(); +} diff --git a/Content.Shared/Sound/SharedEmitSoundSystem.cs b/Content.Shared/Sound/SharedEmitSoundSystem.cs index cd7828fc6b..329626964e 100644 --- a/Content.Shared/Sound/SharedEmitSoundSystem.cs +++ b/Content.Shared/Sound/SharedEmitSoundSystem.cs @@ -41,6 +41,7 @@ public abstract class SharedEmitSoundSystem : EntitySystem SubscribeLocalEvent(OnEmitSoundOnActivateInWorld); SubscribeLocalEvent(OnEmitSoundOnPickup); SubscribeLocalEvent(OnEmitSoundOnDrop); + SubscribeLocalEvent(OnEmitSoundOnInteractUsing); SubscribeLocalEvent(OnEmitSoundOnCollide); } @@ -102,6 +103,13 @@ public abstract class SharedEmitSoundSystem : EntitySystem TryEmitSound(uid, component, args.User); } + private void OnEmitSoundOnInteractUsing(Entity ent, ref InteractUsingEvent args) + { + if (ent.Comp.Whitelist.IsValid(args.Used, EntityManager)) + { + TryEmitSound(ent, ent.Comp, args.User); + } + } protected void TryEmitSound(EntityUid uid, BaseEmitSoundComponent component, EntityUid? user=null, bool predict=true) { if (component.Sound == null)