diff --git a/EXILED/Exiled.API/Features/Toys/Speaker.cs b/EXILED/Exiled.API/Features/Toys/Speaker.cs index c51b8bcb7..2ca0b2907 100644 --- a/EXILED/Exiled.API/Features/Toys/Speaker.cs +++ b/EXILED/Exiled.API/Features/Toys/Speaker.cs @@ -7,10 +7,14 @@ namespace Exiled.API.Features.Toys { + using System.Collections.Generic; + using AdminToys; using Enums; using Exiled.API.Interfaces; using UnityEngine; + using VoiceChat.Networking; + using VoiceChat.Playbacks; /// /// A wrapper class for . @@ -44,7 +48,7 @@ internal Speaker(SpeakerToy speakerToy) public float Volume { get => Base.NetworkVolume; - set => Base.NetworkVolume = value; + set => Base.NetworkVolume = Mathf.Clamp01(value); } /// @@ -86,6 +90,15 @@ public float MinDistance set => Base.NetworkMinDistance = value; } + /// + /// Gets or sets the controller ID of speaker. + /// + public byte ControllerId + { + get => Base.NetworkControllerId; + set => Base.NetworkControllerId = value; + } + /// /// Creates a new . /// @@ -108,5 +121,24 @@ public static Speaker Create(Vector3? position, Vector3? rotation, Vector3? scal return speaker; } + + /// + /// Plays audio through this speaker. + /// + /// An instance. + /// Targets who will hear the audio. If null, audio will be sent to all players. + public static void Play(AudioMessage message, IEnumerable targets = null) + { + foreach (Player target in targets ?? Player.List) + target.Connection.Send(message); + } + + /// + /// Plays audio through this speaker. + /// + /// Audio samples. + /// The length of the samples array. + /// Targets who will hear the audio. If null, audio will be sent to all players. + public void Play(byte[] samples, int? length = null, IEnumerable targets = null) => Play(new AudioMessage(ControllerId, samples, length ?? samples.Length), targets); } }