Exemplo n.º 1
0
        private void OnActorPlayerAttach(AttachPlayerEvent args)
        {
            // Cannot attach to a deleted entity.
            if (args.Entity.Deleted)
            {
                args.Result = false;
                return;
            }

            var uid = args.Entity.Uid;

            // Check if there was a player attached to the entity already...
            if (ComponentManager.TryGetComponent(uid, out ActorComponent actor))
            {
                // If we're not forcing the attach, this fails.
                if (!args.Force)
                {
                    args.Result = false;
                    return;
                }

                // Set the event's force-kicked session before detaching it.
                args.ForceKicked = actor.PlayerSession;

                // This detach cannot fail, as a player is attached to this entity.
                // It's important to note that detaching the player removes the component.
                RaiseLocalEvent(uid, new DetachPlayerEvent());
            }

            // We add the actor component.
            actor = ComponentManager.AddComponent <ActorComponent>(args.Entity);
            actor.PlayerSession = args.Player;
            args.Player.SetAttachedEntity(args.Entity);
            args.Result = true;

            // TODO: Remove component message.
            args.Entity.SendMessage(actor, new PlayerAttachedMsg(args.Player));

            // The player is fully attached now, raise an event!
            RaiseLocalEvent(uid, new PlayerAttachedEvent(args.Entity, args.Player));
        }
Exemplo n.º 2
0
 private void OnActorPlayerAttach(AttachPlayerEvent args)
 {
     args.Result      = Attach(args.Uid, args.Player, args.Force, out var forceKicked);
     args.ForceKicked = forceKicked;
 }