Ejemplo n.º 1
0
        /// <summary>
        /// Spawns a random <see cref="Vehicle"/>, wraps it and adds it to a specific <see cref="WList{TEntity}"/>.
        /// </summary>
        /// <param name="list">The wrapped list.</param>
        /// <param name="position">The position.</param>
        /// <param name="heading">The heading of the vehicle.</param>
        /// <returns></returns>
        public static WVehicle CreateRandomVehicle(this WList <WVehicle> list, Vector3 position, float heading = 0f)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }

            var vehicle = new WVehicle(list.CallbackManager, World.CreateRandomVehicle(position, heading));

            list.Add(vehicle);

            return(vehicle);
        }
Ejemplo n.º 2
0
        public void OnKeyDown(object sender, KeyEventArgs keyEventArgs)
        {
            Vehicles.OnKeyDown(sender, keyEventArgs);

            switch (keyEventArgs.KeyCode)
            {
            case Keys.F10:
            {
                // Create a vehicle using the Vehicles instance we declared earlier.
                WVehicle vehicle = Vehicles.CreateVehicle(VehicleHash.Adder, Game.PlayerPed.Position.Around(2f));

                // Subscribe to a property called "Health" inside "vehicle.Entity".
                vehicle.Subscribe(vehicle.Entity, "Health", OnHealthChanged);

                break;
            }
            }
        }