Esempio n. 1
0
        private void Save()
        {
            foreach (Tuple <Type, int> trackedVehicle in this.Tracked)
            {
                int vehicleHandle = API.NetToVeh(trackedVehicle.Item2);
                var citVeh        = new CitizenFX.Core.Vehicle(vehicleHandle);
                int netId         = API.NetworkGetNetworkIdFromEntity(citVeh.Handle);

                //Debug.WriteLine($"Saving Vehicle: {trackedVehicle.Item2} - {citVeh.Position}");

                Core.Models.Objects.Vehicles.Vehicle vehicle = (Core.Models.Objects.Vehicles.Vehicle)citVeh;
                vehicle.TrackingUserId = Client.Instance.Controllers.First <UserController>().User.Id;
                vehicle.NetId          = netId;
                vehicle.Hash           = citVeh.Model.Hash;

                switch (trackedVehicle.Item1.VehicleType().Name)
                {
                case "Car":
                    //Car car = (Car)vehicle;
                    // Add car specific props...
                    //BaseScript.TriggerServerEvent($"igi:{trackedVehicle.Item1.VehicleType().Name}:save", JsonConvert.SerializeObject(car));
                    Server.Event($"igi:{trackedVehicle.Item1.VehicleType().Name}:save")
                    .Attach(vehicle)
                    .Trigger();
                    break;

                default:
                    //BaseScript.TriggerServerEvent($"igi:{trackedVehicle.Item1.VehicleType().Name}:save", JsonConvert.SerializeObject(vehicle, trackedVehicle.Item1, new JsonSerializerSettings()));
                    Server.Event($"igi:{trackedVehicle.Item1.VehicleType().Name}:save")
                    .Attach(vehicle)
                    .Trigger();
                    break;
                }
            }
        }
Esempio n. 2
0
        private async Task Save()
        {
            foreach (TrackedVehicle trackedVehicle in this.Tracked)
            {
                int vehicleHandle = API.NetToVeh(trackedVehicle.NetId);
                var citVeh        = new CitizenFX.Core.Vehicle(vehicleHandle);
                int netId         = API.NetworkGetNetworkIdFromEntity(citVeh.Handle);

                Core.Models.Objects.Vehicles.Vehicle vehicle = await citVeh.ToVehicle(trackedVehicle.Id);

                vehicle.TrackingUserId = Client.Instance.Controllers.First <UserController>().User.Id;
                vehicle.NetId          = netId;
                vehicle.Hash           = citVeh.Model.Hash;

                switch (trackedVehicle.Type.VehicleType().Name)
                {
                case "Car":
                    //Car car = (Car)vehicle;
                    // Add car specific props...
                    Server.Event($"igi:{trackedVehicle.Type.VehicleType().Name}:save")
                    .Attach(vehicle)
                    .Trigger();
                    break;

                default:
                    Server.Event($"igi:{trackedVehicle.Type.VehicleType().Name}:save")
                    .Attach(vehicle)
                    .Trigger();
                    break;
                }
            }
        }
Esempio n. 3
0
        public static async Task <Vehicle> ToCitizenVehicle(this Core.Models.Objects.Vehicles.Vehicle vehicle)
        {
            Vehicle citizenVehicle = await World.CreateVehicle(new Model((VehicleHash)vehicle.Hash), vehicle.Position, vehicle.Heading);

            citizenVehicle.BodyHealth              = vehicle.BodyHealth;
            citizenVehicle.EngineHealth            = vehicle.EngineHealth;
            citizenVehicle.DirtLevel               = vehicle.DirtLevel;
            citizenVehicle.FuelLevel               = vehicle.FuelLevel;
            citizenVehicle.OilLevel                = vehicle.OilLevel;
            citizenVehicle.PetrolTankHealth        = vehicle.PetrolTankHealth;
            citizenVehicle.TowingCraneRaisedAmount = vehicle.TowingCraneRaisedAmount;
            //citizenVehicle.HasAlarm = vehicle.HasAlarm;
            citizenVehicle.IsAlarmSet = vehicle.IsAlaramed;
            //citizenVehicle.HasLock = vehicle.HasLock;
            citizenVehicle.IsDriveable     = vehicle.IsDriveable;
            citizenVehicle.IsEngineRunning = vehicle.IsEngineRunning;
            //citizenVehicle.HasSeatbelts = vehicle.HasSeatbelts;
            citizenVehicle.AreHighBeamsOn          = vehicle.IsHighBeamsOn;
            citizenVehicle.AreLightsOn             = vehicle.IsLightsOn;
            citizenVehicle.IsInteriorLightOn       = vehicle.IsInteriorLightOn;
            citizenVehicle.IsSearchLightOn         = vehicle.IsSearchLightOn;
            citizenVehicle.IsTaxiLightOn           = vehicle.IsTaxiLightOn;
            citizenVehicle.IsLeftIndicatorLightOn  = vehicle.IsLeftIndicatorLightOn;
            citizenVehicle.IsRightIndicatorLightOn = vehicle.IsRightIndicatorLightOn;
            //citizenVehicle.IsFrontBumperBrokenOff = vehicle.IsFrontBumperBrokenOff;
            //citizenVehicle.IsRearBumperBrokenOff = vehicle.IsRearBumperBrokenOff;
            citizenVehicle.IsLeftHeadLightBroken  = vehicle.IsLeftHeadLightBroken;
            citizenVehicle.IsRightHeadLightBroken = vehicle.IsRightHeadLightBroken;
            citizenVehicle.IsRadioEnabled         = vehicle.IsRadioEnabled;
            citizenVehicle.RoofState         = vehicle.IsRoofOpen ? VehicleRoofState.Opened : VehicleRoofState.Closed;
            citizenVehicle.NeedsToBeHotwired = vehicle.NeedsToBeHotwired;
            citizenVehicle.CanTiresBurst     = vehicle.CanTiresBurst;

            if (vehicle.PrimaryColor.StockColor.HasValue)
            {
                citizenVehicle.Mods.PrimaryColor = (VehicleColor)(int)vehicle.PrimaryColor.StockColor.Value;
            }
            else
            {
                citizenVehicle.Mods.CustomPrimaryColor = vehicle.PrimaryColor.CustomColor.Value;
            }

            if (vehicle.SecondaryColor.StockColor.HasValue)
            {
                citizenVehicle.Mods.SecondaryColor = (VehicleColor)(int)vehicle.SecondaryColor.StockColor.Value;
            }
            else
            {
                citizenVehicle.Mods.CustomPrimaryColor = vehicle.SecondaryColor.CustomColor.Value;
            }

            citizenVehicle.Mods.WindowTint = (VehicleWindowTint)(int)vehicle.WindowTint;
            citizenVehicle.LockStatus      = (VehicleLockStatus)(int)vehicle.LockStatus;
            citizenVehicle.RadioStation    = (RadioStation)(int)vehicle.RadioStation;
            //citizenVehicle.ClassType = (CitizenFX.Core.VehicleClass)(int)vehicle.Class;
            citizenVehicle.Heading = vehicle.Heading;

            return(citizenVehicle);
        }
Esempio n. 4
0
        public static async Task <Vehicle> ToCitizenVehicle(this Core.Models.Objects.Vehicles.Vehicle vehicle)
        {
            Vehicle citizenVehicle = await World.CreateVehicle(new Model((VehicleHash)vehicle.Hash), vehicle.Position, vehicle.Heading);

            citizenVehicle.BodyHealth              = vehicle.BodyHealth;
            citizenVehicle.EngineHealth            = vehicle.EngineHealth;
            citizenVehicle.DirtLevel               = vehicle.DirtLevel;
            citizenVehicle.FuelLevel               = vehicle.FuelLevel;
            citizenVehicle.OilLevel                = vehicle.OilLevel;
            citizenVehicle.PetrolTankHealth        = vehicle.PetrolTankHealth;
            citizenVehicle.TowingCraneRaisedAmount = vehicle.TowingCraneRaisedAmount;
            //veh.HasAlarm = carToSpawn.HasAlarm;
            citizenVehicle.IsAlarmSet = vehicle.IsAlaramed;
            //veh.HasLock = carToSpawn.HasLock;
            citizenVehicle.IsDriveable     = vehicle.IsDriveable;
            citizenVehicle.IsEngineRunning = vehicle.IsEngineRunning;
            //veh.HasSeatbelts = carToSpawn.HasSeatbelts;
            citizenVehicle.CanTiresBurst = vehicle.CanTiresBurst;

            return(citizenVehicle);
        }