public override void Init() { Script.UnhandledException += (object o, Exception e) => { if (DebugSpam) { Log.Write("UnhandledException", "[" + (o?.ToString() ?? "NULL") + "] " + e.ToString()); } }; SoundSettings.Loudness = LoudnessPercentToDb(LoudnessPct); Admins.AddRange(AdminHandles.Trim().ToLower().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); Admins.Add(ScenePrivate.SceneInfo.AvatarId); OriginalOrientation = ObjectPrivate.InitialRotation; OriginalPosition = ObjectPrivate.InitialPosition; if (ObjectPrivate.TryGetFirstComponent(out RigidBody)) { if (!RigidBody.GetCanGrab()) { RigidBody.SetCanGrab(true, (data) => { if (!data.Success) { Log.Write("Could not set ModHammer to grabbable - won't be able to pick up the gun."); } }); } RigidBody.SubscribeToHeldObject(HeldObjectEventType.Grab, OnPickup); RigidBody.SubscribeToHeldObject(HeldObjectEventType.Release, OnDrop); } ScenePrivate.User.Subscribe("AddUser", AddUser); if (BanDuration > 0) { Timer.Create(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), CleanupBans); } }
public override void Init() { if (!ObjectPrivate.TryGetFirstComponent(out _rb)) { Log.Write(LogLevel.Error, "HeldObjectCommandScript can't find a RigidBodyComponent!"); return; } if (!_rb.GetCanGrab()) { Log.Write(LogLevel.Error, "HeldObjectCommandScript isn't on a grabbable object!"); return; } // Subscribe to the "PrimaryAction" action when the object is picked up _rb.SubscribeToHeldObject(HeldObjectEventType.Grab, (HeldObjectData holdData) => { AgentPrivate agent = ScenePrivate.FindAgent(holdData.HeldObjectInfo.SessionId); if (agent != null && agent.IsValid) { _commandSubscription = agent.Client.SubscribeToCommand("PrimaryAction", CommandAction.Pressed, (CommandData command) => { Log.Write(agent.AgentInfo.Name + " pressed the button while holding the object!"); }, (canceledData) => { }); } }); // Unsubscribe from the "PrimaryAction" action when the object is dropped _rb.SubscribeToHeldObject(HeldObjectEventType.Release, (HeldObjectData holdData) => { if (_commandSubscription != null) { _commandSubscription.Unsubscribe(); _commandSubscription = null; } }); }