public class SoundHotkeys : SceneObjectScript
public SoundResource Sound;
public float Volume_Diff_Percent;
private PlayHandle playHandle = null;
private AudioComponent audioComp = null;
private PlaySettings playSettings;
public override void Init()
playSettings.Looping = Looped;
playSettings.Loudness = RelativePercentToRelativeLoudnessDB(Volume_Diff_Percent);
ObjectPrivate.TryGetFirstComponent(out audioComp);
ScenePrivate.User.Subscribe(User.AddUser, NewUser);
private float RelativePercentToRelativeLoudnessDB(float loudnessPercent)
float clampedPercent = Math.Max(-100.0f, Math.Min(150.0f, loudnessPercent));
float multiplier = 0.01f * clampedPercent;
return 24.0f * (multiplier - 1.0f);
private void StartSound(string BehaviorName, ComponentId ComponentId)
StopSound(BehaviorName, ComponentId);
playHandle = ScenePrivate.PlaySound(Sound, playSettings);
playHandle = audioComp.PlaySoundOnComponent(Sound, playSettings);
private void StopSound(string BehaviorName, ComponentId ComponentId)
private void OnOwnerJoined(SessionId userId)
AgentPrivate agent = ScenePrivate.FindAgent(userId);
ObjectPrivate agentObejct = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);
Log.Write($"Unable to find a ObjectPrivate component for user {userId}");
AnimationComponent animationComponent = null;
if (!agentObejct.TryGetFirstComponent(out animationComponent))
Log.Write($"Unable to find an animation component on user {userId}");
animationComponent.Subscribe(StartKey, StartSound);
animationComponent.Subscribe(StopKey, StopSound);
void NewUser(string Action, SessionId User, string Data)
AgentPrivate agent = ScenePrivate.FindAgent(User);
if (ScenePrivate.SceneInfo.AvatarUuid == agent.AgentInfo.AvatarUuid)