Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        private void Subscribe(ScriptEventData data)
        {
            unsubscribes = SubscribeToAll(EnableGrabEvent, (ScriptEventData subdata) =>
            {
                rigidBody.SetCanGrab(true);
            });

            unsubscribes += SubscribeToAll(DisableGrabEvent, (ScriptEventData subData) =>
            {
                rigidBody.SetCanGrab(false);
            });

            if (!string.IsNullOrWhiteSpace(GrabbedMessage))
            {
                grabSubscribe = rigidBody.SubscribeToHeldObject(HeldObjectEventType.Grab, (HeldObjectData holdData) =>
                {
                    if (ShouldSend(holdData))
                    {
                        SendToAll(GrabbedMessage, GrabReleaseData(holdData));
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(ReleasedMessage))
            {
                releaseSubscribe = rigidBody.SubscribeToHeldObject(HeldObjectEventType.Release, (HeldObjectData holdData) =>
                {
                    if (ShouldSend(holdData))
                    {
                        SendToAll(ReleasedMessage, GrabReleaseData(holdData));
                    }
                });
            }
        }
Exemplo n.º 3
0
        bool Reset(RigidBodyComponent rigidBody)
        {
            if (!rigidBody.IsValid)
            {
                Log.Write(LogLevel.Warning, __SimpleTag, "Position Reset: object is no longer in the scene, removing from reset script.");
                return(false);
            }

            if (rigidBody.GetHeldObjectInfo().IsHeld)
            {
                // Check now that the object is still in the scene.
                if (null == ScenePrivate.FindObject(rigidBody.ComponentId.ObjectId))
                {
                    return(false);
                }

                if (ForceDrop)
                {
                    rigidBody.ReleaseHeldObject((d) => { ResetToInitialPosition(rigidBody); });
                }
                else
                {
                    rigidBody.SubscribeToHeldObject(HeldObjectEventType.Release, (d) => { ResetToInitialPosition(rigidBody); }, false);
                }
                return(true);
            }
            else
            {
                return(ResetToInitialPosition(rigidBody));
            }
        }
Exemplo n.º 4
0
 void Reset(ScriptEventData data)
 {
     if (RigidBody.GetHeldObjectInfo().IsHeld)
     {
         RigidBody.SubscribeToHeldObject(HeldObjectEventType.Release, (d) => { ResetToInitialPosition(); }, false);
     }
     else
     {
         ResetToInitialPosition();
     }
 }
    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;
            }
        });
    }
Exemplo n.º 6
0
    public override void Init()
    {
        if (!ObjectPrivate.TryGetFirstComponent(out _rb))
        {
            Log.Write(LogLevel.Error, "FlashlightScript can't find a RigidBodyComponent!");
            return;
        }

        if (!ObjectPrivate.TryGetFirstComponent(out _light) || _light.IsScriptable)
        {

        }

        _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) =>
                {
                    // Do 
                },
                (canceledData) => { });
            }
        }

        _rb.SubscribeToHeldObject(HeldObjectEventType.Release, (HeldObjectData holdData) =>
        {
            if (_commandSubscription != null)
            {
                _commandSubscription.Unsubscribe();
                _commandSubscription = null;
            }
        });
    }