Esempio n. 1
0
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var playerEntity = SampEntities.GetPlayerId((int)context.Arguments[0]);

            var objectType = (int)context.Arguments[1];
            var objectId   = (int)context.Arguments[2];

            var objectEntity = objectType == (int)ObjectType.PlayerObject
                ? SampEntities.GetPlayerObjectId(playerEntity, objectId)
                : SampEntities.GetObjectId(objectId);

            if (!entityManager.Exists(playerEntity))
            {
                return(null);
            }

            // Allow unknown objects to be passed through to the event.

            _context.BaseContext = context;

            _context.Arguments[0] = playerEntity;
            _context.Arguments[1] = objectEntity;
            _context.Arguments[2] = context.Arguments[3];                     // modelId
            _context.Arguments[3] = new Vector3((float)context.Arguments[4], (float)context.Arguments[5],
                                                (float)context.Arguments[6]); // position

            return(_next(_context));
        }
        public object Invoke(EventContext context)
        {
            var inArgs       = context.Arguments;
            var playerEntity = SampEntities.GetPlayerId((int)inArgs[0]);

            var isPlayerObject = (bool)inArgs[1];
            var objectId       = (int)inArgs[2];

            var objectEntity = isPlayerObject
                ? SampEntities.GetPlayerObjectId(playerEntity, objectId)
                : SampEntities.GetObjectId(objectId);

            // Allow unknown objects to be passed through to the event.

            _context.BaseContext = context;

            var args = _context.Arguments;

            args[0] = playerEntity;
            args[1] = objectEntity;
            args[2] = inArgs[3];                                                         // response
            args[3] = new Vector3((float)inArgs[4], (float)inArgs[5], (float)inArgs[6]); // position
            args[4] = new Vector3((float)inArgs[7], (float)inArgs[8], (float)inArgs[9]); // rotation

            return(_next(_context));
        }
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var inArgs       = context.Arguments;
            var playerEntity = SampEntities.GetPlayerId((int)inArgs[0]);

            if (!entityManager.Exists(playerEntity))
            {
                return(null);
            }

            _context.BaseContext = context;

            var args = _context.Arguments;

            args[0] = playerEntity;
            args[1] = inArgs[1];                                                            // response
            args[2] = inArgs[2];                                                            // index
            args[3] = inArgs[3];                                                            // modelId
            args[4] = inArgs[4];                                                            // bone
            args[5] = new Vector3((float)inArgs[5], (float)inArgs[6], (float)inArgs[7]);    // offset
            args[6] = new Vector3((float)inArgs[8], (float)inArgs[9], (float)inArgs[10]);   // rotation
            args[7] = new Vector3((float)inArgs[11], (float)inArgs[12], (float)inArgs[13]); // scale

            return(_next(_context));
        }
Esempio n. 4
0
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var inArgs       = context.Arguments;
            var playerEntity = SampEntities.GetPlayerId((int)inArgs[0]);

            if (!entityManager.Exists(playerEntity))
            {
                return(null);
            }

            var hitType = (int)context.Arguments[2];
            var hitId   = (int)context.Arguments[3];

            EntityId hit;

            switch ((BulletHitType)hitType)
            {
            case BulletHitType.Vehicle:
                hit = SampEntities.GetVehicleId(hitId);
                break;

            case BulletHitType.Object:
                hit = SampEntities.GetObjectId(hitId);
                break;

            case BulletHitType.Player:
                hit = SampEntities.GetPlayerId(hitId);
                break;

            case BulletHitType.PlayerObject:
                hit = SampEntities.GetPlayerObjectId(playerEntity, hitId);
                break;

            default:
                hit = default;
                break;
            }

            // It could be the hit entity does not exist, for instance if it is a player object created by
            // the streamer plugin. We can't however dismiss this event or else the user will not be able
            // to handle the event in some other way.

            _context.BaseContext = context;

            var args = _context.Arguments;

            args[0] = playerEntity;
            args[1] = inArgs[1];                                                         // weapon
            args[2] = hit;
            args[3] = new Vector3((float)inArgs[4], (float)inArgs[5], (float)inArgs[6]); // position

            return(_next(_context));
        }
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            // TODO: Parenting to connection
            var entity = SampEntities.GetPlayerId((int)context.Arguments[0]);

            entityManager.Create(entity);
            entityManager.AddComponent <NativePlayer>(entity);
            entityManager.AddComponent <Player>(entity);

            context.Arguments[0] = entity;

            return(_next(context));
        }
Esempio n. 6
0
        /// <inheritdoc />
        public bool TryParse(IServiceProvider services, ref string inputText, out object result)
        {
            if (!_wordParser.TryParse(services, ref inputText, out var subResult) ||
                !(subResult is string word))
            {
                result = null;
                return(false);
            }

            var entityManager = services.GetRequiredService <IEntityManager>();

            if (int.TryParse(word, out var intWord))
            {
                var entity = SampEntities.GetPlayerId(intWord);

                if (entityManager.Exists(entity))
                {
                    result = entity;
                    return(true);
                }
            }

            var      players       = entityManager.GetComponents <Player>();
            EntityId bestCandidate = null;

            foreach (Player player in players)
            {
                if (player.Name.Equals(word, StringComparison.OrdinalIgnoreCase))
                {
                    result = player.Entity;
                    return(true);
                }

                if (player.Name.ToLower().StartsWith(word.ToLower()))
                {
                    if (bestCandidate == null)
                    {
                        bestCandidate = player.Entity;
                    }
                    else if (player.Entity.Handle < bestCandidate.Handle)
                    {
                        bestCandidate = player.Entity;
                    }
                }
            }

            result = bestCandidate;
            return(bestCandidate != null);
        }
Esempio n. 7
0
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var playerEntity = SampEntities.GetPlayerId((int)context.Arguments[0]);

            if (!entityManager.Exists(playerEntity))
            {
                return(null);
            }

            _context.BaseContext  = context;
            _context.Arguments[0] = playerEntity;
            _context.Arguments[1] = new Vector3((float)context.Arguments[1], (float)context.Arguments[2], (float)context.Arguments[3]); // position

            return(_next(_context));
        }
Esempio n. 8
0
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var playerEntity = SampEntities.GetPlayerId((int)context.Arguments[0]);
            var objectEntity = SampEntities.GetPlayerObjectId(playerEntity, (int)context.Arguments[1]);

            if (!entityManager.Exists(playerEntity))
            {
                return(null);
            }

            // Allow unknown objects to be passed through to the event.

            context.Arguments[0] = playerEntity;
            context.Arguments[1] = objectEntity;

            return(_next(context));
        }
Esempio n. 9
0
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var entity = SampEntities.GetPlayerId((int)context.Arguments[0]);

            if (!entityManager.Exists(entity))
            {
                return(null);
            }

            context.Arguments[0] = entity;

            var result = _next(context);

            entityManager.Destroy(entity);

            return(result);
        }
        public object Invoke(EventContext context, IEventService eventService, IEntityManager entityManager)
        {
            var playerEntity   = SampEntities.GetPlayerId((int)context.Arguments[0]);
            var textDrawEntity = SampEntities.GetTextDrawId((int)context.Arguments[1]);

            if (!entityManager.Exists(playerEntity))
            {
                return(null);
            }

            // Allow unknown text draws to be passed through to the event.

            // Forward to OnPlayerCancelTextDraw and cancel continuation OnPlayerClickTextDraw event.
            if (textDrawEntity == NativeTextDraw.InvalidId)
            {
                return(eventService.Invoke("OnPlayerCancelTextDraw", playerEntity));
            }

            context.Arguments[0] = playerEntity;
            context.Arguments[1] = textDrawEntity;

            return(_next(context));
        }
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var inArgs        = context.Arguments;
            var vehicleEntity = SampEntities.GetVehicleId((int)inArgs[0]);
            var playerEntity  = SampEntities.GetPlayerId((int)inArgs[1]);

            if (!entityManager.Exists(playerEntity) || !entityManager.Exists(vehicleEntity))
            {
                return(null);
            }

            _context.BaseContext = context;

            var args = _context.Arguments;

            args[0] = vehicleEntity;
            args[1] = playerEntity;
            args[2] = inArgs[2];                                                         // passengerSeat
            args[3] = new Vector3((float)inArgs[3], (float)inArgs[4], (float)inArgs[5]); // newPosition
            args[4] = new Vector3((float)inArgs[6], (float)inArgs[7], (float)inArgs[8]); // velocity

            return(_next(_context));
        }