diff --git a/vMenu/CommonFunctions.cs b/vMenu/CommonFunctions.cs index ff3960f5..a5885f2b 100644 --- a/vMenu/CommonFunctions.cs +++ b/vMenu/CommonFunctions.cs @@ -1237,6 +1237,11 @@ public static async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool r } vehicle.CurrentRPM = rpm; + await Delay(1); // Mandatory delay - without it radio station will not set properly + + // Set the radio station to default set by player in Vehicle Menu + vehicle.RadioStation = (RadioStation)UserDefaults.VehicleDefaultRadio; + // Discard the model. SetModelAsNoLongerNeeded(vehicleHash); } diff --git a/vMenu/UserDefaults.cs b/vMenu/UserDefaults.cs index d046bb9c..751ddef1 100644 --- a/vMenu/UserDefaults.cs +++ b/vMenu/UserDefaults.cs @@ -159,6 +159,12 @@ public static bool VehicleBikeSeatbelt get { return GetSettingsBool("vehicleBikeSeatbelt"); } set { SetSavedSettingsBool("vehicleBikeSeatbelt", value); } } + + public static int VehicleDefaultRadio + { + get { return GetSettingsInt("vehicleDefaultRadio"); } + set { SetSavedSettingsInt("vehicleDefaultRadio", value); } + } #endregion #region Vehicle Spawner Options diff --git a/vMenu/menus/VehicleOptions.cs b/vMenu/menus/VehicleOptions.cs index 47fef631..55169af3 100644 --- a/vMenu/menus/VehicleOptions.cs +++ b/vMenu/menus/VehicleOptions.cs @@ -134,6 +134,23 @@ private void CreateMenu() }; MenuListItem vehicleLights = new MenuListItem("Vehicle Lights", lights, 0, "Turn vehicle lights on/off."); + List stationNames = new List(); + + foreach (var radioStationName in Enum.GetNames(typeof(RadioStation))) + { + stationNames.Add(radioStationName); + } + + int radioIndex = UserDefaults.VehicleDefaultRadio; + + if (radioIndex == (int)RadioStation.RadioOff) + { + RadioStation[] stations = (RadioStation[])Enum.GetValues(typeof(RadioStation)); + int index = Array.IndexOf(stations, RadioStation.RadioOff); + radioIndex = index; + } + + MenuListItem radioStations = new MenuListItem("Default radio station", stationNames, radioIndex, "Select a defalut radio station to be set when spawning new car"); var tiresList = new List() { "All Tires", "Tire #1", "Tire #2", "Tire #3", "Tire #4", "Tire #5", "Tire #6", "Tire #7", "Tire #8" }; MenuListItem vehicleTiresList = new MenuListItem("Fix / Destroy Tires", tiresList, 0, "Fix or destroy a specific vehicle tire, or all of them at once. Note, not all indexes are valid for all vehicles, some might not do anything on certain vehicles."); @@ -369,6 +386,9 @@ private void CreateMenu() } // always allowed menu.AddMenuItem(showHealth); // SHOW VEHICLE HEALTH + + // I don't really see why would you want to disable this so I will not add useless permissions + menu.AddMenuItem(radioStations); if (IsAllowed(Permission.VONoSiren) && !vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.vmenu_use_els_compatibility_mode)) // DISABLE SIREN { @@ -897,6 +917,17 @@ private void CreateMenu() { Notify.Error(CommonErrors.NoVehicle); } + } else if (item == radioStations) + { + RadioStation newStation = (RadioStation)Enum.GetValues(typeof(RadioStation)).GetValue(listIndex); + + var veh = GetVehicle(); + if (veh != null && veh.Exists()) + { + veh.RadioStation = newStation; + } + + UserDefaults.VehicleDefaultRadio = (int) newStation; } }; #endregion