예제 #1
0
        public void OnVehicleExplode(NetHandle vehicle)
        {
            var vehicleController = EntityManager.GetVehicle(vehicle);

            if (vehicleController == null)
            {
                return;
            }
            if (!vehicleController.VehicleData.Respawnable)
            {
                return;
            }

            var vehicleData = vehicleController.VehicleData;

            EntityManager.Warning("Транспортное средство: " + vehicleData.Model + " было уничтожено.");
            API.delay(30000, true, () =>
            {
                EntityManager.Success("Транспортное средство: " + vehicleData.Model + " было респавнено.");

                vehicleController.Vehicle.delete();

                vehicleData.Fuel = FuelByType.GetFuel(vehicleData.Model);

                var newVehicle = new VehicleController(vehicleData,
                                                       API.shared.createVehicle((VehicleHash)vehicleData.Model,
                                                                                new Vector3(vehicleData.PosX, vehicleData.PosY, vehicleData.PosZ),
                                                                                new Vector3(0.0f, 0.0f, vehicleData.Rot), vehicleData.Color1, vehicleData.Color2));
            });
        }
예제 #2
0
        private void VehicleFuelEvent()
        {
            if (DateTime.Now.Subtract(_oneSecond).TotalMilliseconds >= 500)
            {
                try
                {
                    var allVehicles = API.getAllVehicles();
                    foreach (var vehicle in allVehicles)
                    {
                        if (API.getVehicleEngineStatus(vehicle))
                        {
                            var vehicleController = EntityManager.GetVehicle(vehicle);

                            if (vehicleController != null)
                            {
                                if (_inVehiclePlayer.vehicle == vehicle)
                                {
                                    _currentFuel = vehicleController.VehicleData.Fuel;
                                    vehicleController.VehicleData.Fuel -=
                                        _vehRpm * FuelByType.GetConsumption(vehicleController.VehicleData.Model);

                                    if (_currentFuel - vehicleController.VehicleData.Fuel > 0.2)
                                    {
                                        _currentFuel = vehicleController.VehicleData.Fuel;
                                        ContextFactory.Instance.SaveChangesAsync();
                                    }
                                    if (_currentFuel < 0)
                                    {
                                        _currentFuel = 0.0;
                                        vehicleController.VehicleData.Fuel = 0.0;
                                        ContextFactory.Instance.SaveChangesAsync();
                                        vehicleController.Vehicle.engineStatus = false;
                                    }
                                }
                                else
                                {
                                    vehicleController.VehicleData.Fuel -=
                                        _vehRpm * FuelByType.GetConsumption(vehicleController.VehicleData.Model);
                                    ContextFactory.Instance.SaveChangesAsync();
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    EntityManager.Log(e, "VEHICLE FUEL DEBUG");
                }

                _oneSecond = DateTime.Now;
            }
        }
예제 #3
0
        private void RespawnStaticGroupVehicle(int groupId)
        {
            var allStaticVehicles = ContextFactory.Instance.Vehicle.Where(x => x.GroupId == groupId);

            foreach (var vehicle in allStaticVehicles)
            {
                var vehicleController = EntityManager.GetVehicle(vehicle);
                var vehiclePostition  = new Vector3(vehicle.PosX, vehicle.PosY, vehicle.PosZ);

                if (vehicleController.Vehicle.occupants.Length == 0 &&
                    vehicleController.Vehicle.position != vehiclePostition)
                {
                    vehicleController.Vehicle.delete();

                    vehicle.Fuel = FuelByType.GetFuel(vehicle.Model);
                    var newVehicle = new VehicleController(vehicle,
                                                           API.shared.createVehicle((VehicleHash)vehicle.Model,
                                                                                    new Vector3(vehicle.PosX, vehicle.PosY, vehicle.PosZ),
                                                                                    new Vector3(0.0f, 0.0f, vehicle.Rot), vehicle.Color1, vehicle.Color2));
                }
            }
            ContextFactory.Instance.SaveChanges();
        }