示例#1
0
        /// <summary>
        /// Updates the <see cref="CurrentVehicle"/> and the <see cref="CurrentPreset"/>
        /// </summary>
        /// <returns></returns>
        private async Task GetCurrentVehicle()
        {
            PlayerPed = PlayerPedId();

            if (IsPedInAnyVehicle(PlayerPed, false))
            {
                int vehicle = GetVehiclePedIsIn(PlayerPed, false);

                if (VehiclesPermissions.IsVehicleAllowed(vehicle) && GetPedInVehicleSeat(vehicle, -1) == PlayerPed && !IsEntityDead(vehicle))
                {
                    // Update current vehicle and get its preset
                    if (vehicle != CurrentVehicle)
                    {
                        CurrentVehicle = vehicle;
                        CurrentPreset  = CreateHandlingPreset(CurrentVehicle);
                        PresetChanged?.Invoke(this, EventArgs.Empty);
                    }
                }
                else
                {
                    // If current vehicle isn't a car or player isn't driving current vehicle or vehicle is dead
                    CurrentVehicle = -1;
                    CurrentPreset  = null;
                }
            }
            else
            {
                // If player isn't in any vehicle
                CurrentVehicle = -1;
                CurrentPreset  = null;
            }

            await Task.FromResult(0);
        }
示例#2
0
        private async void GUI_MenuApplyServerPresetButtonPressed(object sender, string presetName)
        {
            if (ServerPresets.TryGetValue(presetName, out HandlingPreset preset))
            {
                var presetFields = preset.Fields;
                foreach (var field in presetFields.Keys)
                {
                    // TODO: Add a flag to decide if a field should be added to the preset anyway
                    if (CurrentPreset.Fields.ContainsKey(field))
                    {
                        CurrentPreset.Fields[field] = presetFields[field];
                    }
                    else
                    {
                        CitizenFX.Core.Debug.Write($"Missing {field} field in currentPreset");
                    }
                }

                PresetChanged?.Invoke(this, EventArgs.Empty);
                Screen.ShowNotification($"{ScriptName}: Server preset ~b~{presetName}~w~ applied");
            }
            else
            {
                Screen.ShowNotification($"{ScriptName}: ~r~ERROR~w~ Server preset ~b~{presetName}~w~ corrupted");
            }

            await Delay(200);
        }
示例#3
0
        private async void GUI_MenuResetPresetButtonPressed(object sender, EventArgs e)
        {
            CurrentPreset.Reset();
            RemoveDecorators(CurrentVehicle);
            RefreshVehicleUsingPreset(CurrentVehicle, CurrentPreset);

            await Delay(200);

            PresetChanged?.Invoke(this, EventArgs.Empty);
        }
        /// <summary>
        /// Invoked when the reset button is pressed in the UI
        /// </summary>
        private async void OnMenuResetPresetButtonPressed()
        {
            if (!CurrentPresetIsValid)
            {
                return;
            }

            currentPreset.Reset();
            RemoveDecorators(currentVehicle);

            // Force one single refresh to update rendering at correct position after reset
            // This is required because otherwise the vehicle won't update immediately
            RefreshVehicleUsingPreset(currentVehicle, currentPreset);

            await Delay(200);

            PresetChanged?.Invoke(this, EventArgs.Empty);
        }
        /// <summary>
        /// Updates the <see cref="currentVehicle"/> and the <see cref="currentPreset"/>
        /// </summary>
        /// <returns></returns>
        private async Task GetCurrentVehicle()
        {
            playerPed = PlayerPedId();

            if (IsPedInAnyVehicle(playerPed, false))
            {
                int vehicle = GetVehiclePedIsIn(playerPed, false);

                if (IsThisModelACar((uint)GetEntityModel(vehicle)) && GetPedInVehicleSeat(vehicle, -1) == playerPed && IsVehicleDriveable(vehicle, false))
                {
                    // Update current vehicle and get its preset
                    if (vehicle != currentVehicle)
                    {
                        currentPreset  = CreatePreset(vehicle);
                        currentVehicle = vehicle;
                        PresetChanged?.Invoke(this, EventArgs.Empty);
                        Tick += UpdateCurrentVehicle;
                    }
                }
                else
                {
                    if (CurrentPresetIsValid)
                    {
                        // If current vehicle isn't a car or player isn't driving current vehicle or vehicle is dead
                        currentPreset  = null;
                        currentVehicle = -1;
                        Tick          -= UpdateCurrentVehicle;
                    }
                }
            }
            else
            {
                if (CurrentPresetIsValid)
                {
                    // If player isn't in any vehicle
                    currentPreset  = null;
                    currentVehicle = -1;
                    Tick          -= UpdateCurrentVehicle;
                }
            }

            await Task.FromResult(0);
        }
示例#6
0
        private async void GUI_MenuApplyPersonalPresetButtonPressed(object sender, string presetName)
        {
            string key   = $"{kvpPrefix}{presetName}";
            string value = GetResourceKvpString(key);

            if (value != null)
            {
                value = Helpers.RemoveByteOrderMarks(value);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(value);
                var handling = doc["Item"];
                GetPresetFromXml(handling, CurrentPreset);

                PresetChanged?.Invoke(this, EventArgs.Empty);
                Screen.ShowNotification($"{ScriptName}: Personal preset ~b~{presetName}~w~ applied");
            }
            else
            {
                Screen.ShowNotification($"{ScriptName}: ~r~ERROR~w~ Personal preset ~b~{presetName}~w~ corrupted");
            }

            await Delay(200);
        }
        /// <summary>
        /// Loads a Vstancer preset for the <paramref name="vehicle"/> with the specified values.
        /// </summary>
        /// <param name="vehicle">The handle of the entity</param>
        /// <param name="frontOffset">The front offset value</param>
        /// <param name="frontRotation">The front rotation value</param>
        /// <param name="rearOffset">The rear offset value</param>
        /// <param name="rearRotation">The rear rotation value</param>
        /// <param name="steeringLock">Steering lock value</param>
        /// <param name="suspensionHeight">Suspension height value</param>
        /// <param name="defaultFrontOffset">The default front offset value</param>
        /// <param name="defaultFrontRotation">The default front rotation value</param>
        /// <param name="defaultRearOffset">The default rear offset value</param>
        /// <param name="defaultRearRotation">The default rear rotation value</param>
        /// <param name="defaultSteeringLock">The default steering lock value</param>
        /// <param name="defaultSuspensionHeight">The default suspension height value</param>
        public void SetVstancerPreset(int vehicle, float frontOffset, float frontRotation, float rearOffset, float rearRotation, float steeringLock, float suspensionHeight, object defaultFrontOffset = null, object defaultFrontRotation = null, object defaultRearOffset = null, object defaultRearRotation = null, object defaultSteeringLock = null, object defaultSuspensionHeight = null)
        {
            if (debug)
            {
                Debug.WriteLine($"{ScriptName}: SetVstancerPreset parameters {frontOffset} {frontRotation} {rearOffset} {rearRotation} {steeringLock} {suspensionHeight} {defaultFrontOffset} {defaultFrontRotation} {defaultRearOffset} {defaultRearRotation} {defaultSteeringLock} {defaultSuspensionHeight}");
            }

            if (!DoesEntityExist(vehicle))
            {
                return;
            }

            int wheelsCount = GetVehicleNumberOfWheels(vehicle);
            int frontCount  = VStancerPreset.CalculateFrontWheelsCount(wheelsCount);

            float off_f_def, rot_f_def, off_r_def, rot_r_def, steering_lock_def, susp_height_def;

            if (defaultFrontOffset != null && defaultFrontOffset is float)
            {
                off_f_def = (float)defaultFrontOffset;
            }
            else
            {
                off_f_def = DecorExistOn(vehicle, DefaultFrontOffsetID) ? DecorGetFloat(vehicle, DefaultFrontOffsetID) : GetVehicleWheelXOffset(vehicle, 0);
            }

            if (defaultFrontRotation != null && defaultFrontRotation is float)
            {
                rot_f_def = (float)defaultFrontRotation;
            }
            else
            {
                rot_f_def = DecorExistOn(vehicle, DefaultFrontRotationID) ? DecorGetFloat(vehicle, DefaultFrontRotationID) : GetVehicleWheelYRotation(vehicle, 0);
            }

            if (defaultRearOffset != null && defaultRearOffset is float)
            {
                off_r_def = (float)defaultRearOffset;
            }
            else
            {
                off_r_def = DecorExistOn(vehicle, DefaultRearOffsetID) ? DecorGetFloat(vehicle, DefaultRearOffsetID) : GetVehicleWheelXOffset(vehicle, frontCount);
            }

            if (defaultRearRotation != null && defaultRearRotation is float)
            {
                rot_r_def = (float)defaultRearRotation;
            }
            else
            {
                rot_r_def = DecorExistOn(vehicle, DefaultRearRotationID) ? DecorGetFloat(vehicle, DefaultRearRotationID) : GetVehicleWheelYRotation(vehicle, frontCount);
            }

            if (defaultSteeringLock != null && defaultSteeringLock is float)
            {
                steering_lock_def = (float)defaultSteeringLock;
            }
            else
            {
                steering_lock_def = DecorExistOn(vehicle, DefaultSteeringLockID) ? DecorGetFloat(vehicle, DefaultSteeringLockID) : GetVehicleHandlingFloat(vehicle, "CHandlingData", "fSteeringLock");
            }

            if (defaultSuspensionHeight != null && defaultSuspensionHeight is float)
            {
                susp_height_def = (float)defaultSuspensionHeight;
            }
            else
            {
                susp_height_def = DecorExistOn(vehicle, DefaultSuspensionHeightID) ? DecorGetFloat(vehicle, DefaultSuspensionHeightID) : GetVehicleHandlingFloat(vehicle, "CHandlingData", "fSuspensionRaise");
            }

            if (vehicle == currentVehicle)
            {
                currentPreset = new VStancerPreset(wheelsCount, frontOffset, frontRotation, rearOffset, rearRotation, steeringLock, suspensionHeight, off_f_def, rot_f_def, off_r_def, rot_r_def, steering_lock_def, susp_height_def);
                PresetChanged?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                UpdateFloatDecorator(vehicle, DefaultFrontOffsetID, off_f_def, frontOffset);
                UpdateFloatDecorator(vehicle, DefaultFrontRotationID, rot_f_def, frontRotation);
                UpdateFloatDecorator(vehicle, DefaultRearOffsetID, off_r_def, rearOffset);
                UpdateFloatDecorator(vehicle, DefaultRearRotationID, rot_r_def, rearRotation);
                UpdateFloatDecorator(vehicle, DefaultSteeringLockID, steering_lock_def, steeringLock);
                UpdateFloatDecorator(vehicle, DefaultSuspensionHeightID, susp_height_def, suspensionHeight);

                UpdateFloatDecorator(vehicle, FrontOffsetID, frontOffset, off_f_def);
                UpdateFloatDecorator(vehicle, FrontRotationID, frontRotation, rot_f_def);
                UpdateFloatDecorator(vehicle, RearOffsetID, rearOffset, off_r_def);
                UpdateFloatDecorator(vehicle, RearRotationID, rearRotation, rot_r_def);
                UpdateFloatDecorator(vehicle, SteeringLockID, steeringLock, steering_lock_def);
                UpdateFloatDecorator(vehicle, SuspensionHeightID, suspensionHeight, susp_height_def);
            }
        }
示例#8
0
        /// <summary>
        /// Loads a Vstancer preset for the <paramref name="vehicle"/> with the specified values.
        /// </summary>
        /// <param name="vehicle">The handle of the entity</param>
        /// <param name="frontOffset">The front offset value</param>
        /// <param name="frontRotation">The front rotation value</param>
        /// <param name="rearOffset">The rear offset value</param>
        /// <param name="rearRotation">The rear rotation value</param>
        /// <param name="defaultFrontOffset">The default front offset value</param>
        /// <param name="defaultFrontRotation">The default front rotation value</param>
        /// <param name="defaultRearOffset">The default rear offset value</param>
        /// <param name="defaultRearRotation">The default rear rotation value</param>
        public void SetVstancerPreset(int vehicle, float frontOffset, float frontRotation, float rearOffset, float rearRotation, object defaultFrontOffset = null, object defaultFrontRotation = null, object defaultRearOffset = null, object defaultRearRotation = null)
        {
            if (debug)
            {
                Debug.WriteLine($"{ScriptName}: SetVstancerPreset parameters {frontOffset} {frontRotation} {rearOffset} {rearRotation} {defaultFrontOffset} {defaultFrontRotation} {defaultRearOffset} {defaultRearRotation}");
            }

            if (!DoesEntityExist(vehicle))
            {
                return;
            }

            int wheelsCount = GetVehicleNumberOfWheels(vehicle);
            int frontCount  = VStancerPreset.CalculateFrontWheelsCount(wheelsCount);

            float off_f_def, rot_f_def, off_r_def, rot_r_def;

            if (defaultFrontOffset != null && defaultFrontOffset is float)
            {
                off_f_def = (float)defaultFrontOffset;
            }
            else
            {
                off_f_def = DecorExistOn(vehicle, DefaultFrontOffsetID) ? DecorGetFloat(vehicle, DefaultFrontOffsetID) : GetVehicleWheelXOffset(vehicle, 0);
            }

            if (defaultFrontRotation != null && defaultFrontRotation is float)
            {
                rot_f_def = (float)defaultFrontRotation;
            }
            else
            {
                rot_f_def = DecorExistOn(vehicle, DefaultFrontRotationID) ? DecorGetFloat(vehicle, DefaultFrontRotationID) : GetVehicleWheelYRotation(vehicle, 0);
            }

            if (defaultRearOffset != null && defaultRearOffset is float)
            {
                off_r_def = (float)defaultRearOffset;
            }
            else
            {
                off_r_def = DecorExistOn(vehicle, DefaultRearOffsetID) ? DecorGetFloat(vehicle, DefaultRearOffsetID) : GetVehicleWheelXOffset(vehicle, frontCount);
            }

            if (defaultRearRotation != null && defaultRearRotation is float)
            {
                rot_r_def = (float)defaultRearRotation;
            }
            else
            {
                rot_r_def = DecorExistOn(vehicle, DefaultRearRotationID) ? DecorGetFloat(vehicle, DefaultRearRotationID) : GetVehicleWheelYRotation(vehicle, frontCount);
            }

            if (vehicle == currentVehicle)
            {
                currentPreset = new VStancerPreset(wheelsCount, frontOffset, frontRotation, rearOffset, rearRotation, off_f_def, rot_f_def, off_r_def, rot_r_def);
                PresetChanged?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                UpdateFloatDecorator(vehicle, DefaultFrontOffsetID, off_f_def, frontOffset);
                UpdateFloatDecorator(vehicle, DefaultFrontRotationID, rot_f_def, frontRotation);
                UpdateFloatDecorator(vehicle, DefaultRearOffsetID, off_r_def, rearOffset);
                UpdateFloatDecorator(vehicle, DefaultRearRotationID, rot_r_def, rearRotation);

                UpdateFloatDecorator(vehicle, FrontOffsetID, frontOffset, off_f_def);
                UpdateFloatDecorator(vehicle, FrontRotationID, frontRotation, rot_f_def);
                UpdateFloatDecorator(vehicle, RearOffsetID, rearOffset, off_r_def);
                UpdateFloatDecorator(vehicle, RearRotationID, rearRotation, rot_r_def);
            }
        }