Skip to content

Commit 07d79d9

Browse files
authored
Merge pull request #517 from TomGrobbe/development
vMenu v3.8.1
2 parents 67600d7 + 48b5377 commit 07d79d9

File tree

7 files changed

+237
-59
lines changed

7 files changed

+237
-59
lines changed

vMenu/CommonFunctions.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ public static async void SaveVehicle(string updateExistingSavedVehicleName = nul
15341534
#region new saving method
15351535
var mods = new Dictionary<int, int>();
15361536

1537-
foreach (var mod in veh.Mods.GetAllMods())
1537+
foreach (var mod in GetAllVehicleMods(veh))
15381538
{
15391539
mods.Add((int)mod.ModType, mod.Index);
15401540
}
@@ -2046,8 +2046,7 @@ public static Dictionary<string, string> JsonToDictionary(string json)
20462046
/// </summary>
20472047
/// <param name="hours">Hours (0-23)</param>
20482048
/// <param name="minutes">Minutes (0-59)</param>
2049-
/// <param name="freezeTime">Should the time be frozen?</param>
2050-
public static void UpdateServerTime(int hours, int minutes, bool freezeTime)
2049+
public static void UpdateServerTime(int hours, int minutes)
20512050
{
20522051
var realHours = hours;
20532052
var realMinutes = minutes;
@@ -2059,8 +2058,14 @@ public static void UpdateServerTime(int hours, int minutes, bool freezeTime)
20592058
{
20602059
realMinutes = 0;
20612060
}
2062-
TriggerServerEvent("vMenu:UpdateServerTime", realHours, realMinutes, freezeTime);
2061+
TriggerServerEvent("vMenu:UpdateServerTime", realHours, realMinutes);
20632062
}
2063+
2064+
/// <summary>
2065+
/// Updates the server on if time should be frozen or not.
2066+
/// </summary>
2067+
/// <param name="freezeTime">`true` to freeze time, `false` to unfreeze time</param>
2068+
public static void FreezeServerTime(bool freezeTime) => TriggerServerEvent("vMenu:FreezeServerTime", freezeTime);
20642069
#endregion
20652070

20662071
#region StringToStringArray
@@ -3461,5 +3466,26 @@ public static async void SavePlayerLocationToLocationsFile()
34613466
Notify.Success("The location was successfully saved.");
34623467
}
34633468
#endregion
3469+
3470+
#region Get all vehicle mods
3471+
public static VehicleMod[] GetAllVehicleMods(Vehicle vehicle)
3472+
{
3473+
int vehicleHandle = vehicle.Handle;
3474+
3475+
bool HasVehicleMod(VehicleData.ModType modType)
3476+
{
3477+
return GetNumVehicleMods(vehicleHandle, (int)modType) > 0;
3478+
}
3479+
3480+
return
3481+
[
3482+
.. Enum.GetValues(typeof(VehicleData.ModType))
3483+
.Cast<VehicleData.ModType>()
3484+
.Where(HasVehicleMod)
3485+
// The cast to `VehicleModType` is fine here because `VehicleMod` casts `VehicleModType` to `int`
3486+
.Select(modType => vehicle.Mods[(VehicleModType)modType])
3487+
];
3488+
}
3489+
#endregion
34643490
}
34653491
}

vMenu/data/VehicleData.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,5 +1446,62 @@ public static string[] GetAllVehicles()
14461446
return vehs.ToArray();
14471447
}
14481448
}
1449+
1450+
/// <summary>
1451+
/// Values taken from `SET_VEHICLE_MOD` native
1452+
/// </summary>
1453+
public enum ModType
1454+
{
1455+
VMT_SPOILER = 0,
1456+
VMT_BUMPER_F = 1,
1457+
VMT_BUMPER_R = 2,
1458+
VMT_SKIRT = 3,
1459+
VMT_EXHAUST = 4,
1460+
VMT_CHASSIS = 5,
1461+
VMT_GRILL = 6,
1462+
VMT_BONNET = 7,
1463+
VMT_WING_L = 8,
1464+
VMT_WING_R = 9,
1465+
VMT_ROOF = 10,
1466+
VMT_ENGINE = 11,
1467+
VMT_BRAKES = 12,
1468+
VMT_GEARBOX = 13,
1469+
VMT_HORN = 14,
1470+
VMT_SUSPENSION = 15,
1471+
VMT_ARMOUR = 16,
1472+
VMT_NITROUS = 17,
1473+
VMT_TURBO = 18,
1474+
VMT_SUBWOOFER = 19,
1475+
VMT_TYRE_SMOKE = 20,
1476+
VMT_HYDRAULICS = 21,
1477+
VMT_XENON_LIGHTS = 22,
1478+
VMT_WHEELS = 23,
1479+
VMT_WHEELS_REAR_OR_HYDRAULICS = 24,
1480+
VMT_PLTHOLDER = 25,
1481+
VMT_PLTVANITY = 26,
1482+
VMT_INTERIOR1 = 27,
1483+
VMT_INTERIOR2 = 28,
1484+
VMT_INTERIOR3 = 29,
1485+
VMT_INTERIOR4 = 30,
1486+
VMT_INTERIOR5 = 31,
1487+
VMT_SEATS = 32,
1488+
VMT_STEERING = 33,
1489+
VMT_KNOB = 34,
1490+
VMT_PLAQUE = 35,
1491+
VMT_ICE = 36,
1492+
VMT_TRUNK = 37,
1493+
VMT_HYDRO = 38,
1494+
VMT_ENGINEBAY1 = 39,
1495+
VMT_ENGINEBAY2 = 40,
1496+
VMT_ENGINEBAY3 = 41,
1497+
VMT_CHASSIS2 = 42,
1498+
VMT_CHASSIS3 = 43,
1499+
VMT_CHASSIS4 = 44,
1500+
VMT_CHASSIS5 = 45,
1501+
VMT_DOOR_L = 46,
1502+
VMT_DOOR_R = 47,
1503+
VMT_LIVERY_MOD = 48,
1504+
VMT_LIGHTBAR = 49,
1505+
}
14491506
}
14501507
}

vMenu/menus/MpPedCustomization.cs

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class MpPedCustomization
121121
private float _shapeMixValue;
122122
private float _skinMixValue;
123123
private readonly Dictionary<int, int> shapeFaceValues = [];
124-
private readonly Dictionary<int, Tuple<int, int, float>> apperanceValues = [];
124+
private readonly Dictionary<int, Tuple<int, int, float>> appearanceValues = [];
125125
private int _hairSelection;
126126
private int _hairColorSelection;
127127
private int _hairHighlightColorSelection;
@@ -179,6 +179,17 @@ private void MakeCreateCharacterMenu(bool male, bool editPed = false)
179179
propsMenu.ClearMenuItems();
180180

181181
#region appearance menu.
182+
// Clears any saved appearance values from prior peds
183+
_hairSelection = 0;
184+
_hairColorSelection = 0;
185+
_hairHighlightColorSelection = 0;
186+
_eyeColorSelection = 0;
187+
188+
for (int i = 0; i < 12; i++)
189+
{
190+
appearanceValues[i] = new Tuple<int, int, float>(0, 0, 0f);
191+
}
192+
182193
var opacity = new List<string>() { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
183194

184195
var maxHairStyles = GetNumberOfPedDrawableVariations(Game.PlayerPed.Handle, 2);
@@ -1805,6 +1816,7 @@ void ApplySavedTattoos()
18051816
case 1:
18061817
if (!currentCharacter.IsMale)
18071818
{
1819+
appearanceValues[i] = new Tuple<int, int, float>(0, 0, 0f);
18081820
continue;
18091821
}
18101822

@@ -1837,6 +1849,7 @@ void ApplySavedTattoos()
18371849
case 8:
18381850
if (currentCharacter.IsMale)
18391851
{
1852+
appearanceValues[i] = new Tuple<int, int, float>(0, 0, 0f);
18401853
continue;
18411854
}
18421855

@@ -1859,6 +1872,7 @@ void ApplySavedTattoos()
18591872
case 10:
18601873
if (!currentCharacter.IsMale)
18611874
{
1875+
appearanceValues[i] = new Tuple<int, int, float>(0, 0, 0f);
18621876
continue;
18631877
}
18641878

@@ -1879,16 +1893,16 @@ void ApplySavedTattoos()
18791893
break;
18801894

18811895
default:
1882-
apperanceValues[i] = new Tuple<int, int, float>(0, 0, 0);
1896+
appearanceValues[i] = new Tuple<int, int, float>(0, 0, 0);
18831897
continue;
18841898
}
18851899

1886-
apperanceValues[i] = new Tuple<int, int, float>(value, color, opacity);
1887-
SetPedHeadOverlay(Game.PlayerPed.Handle, i, apperanceValues[i].Item1, apperanceValues[i].Item3);
1900+
appearanceValues[i] = new Tuple<int, int, float>(value, color, opacity);
1901+
SetPedHeadOverlay(Game.PlayerPed.Handle, i, appearanceValues[i].Item1, appearanceValues[i].Item3);
18881902

18891903
if (colorRequired)
18901904
{
1891-
SetPedHeadOverlayColor(Game.PlayerPed.Handle, i, colorIndex, apperanceValues[i].Item2, apperanceValues[i].Item2);
1905+
SetPedHeadOverlayColor(Game.PlayerPed.Handle, i, colorIndex, appearanceValues[i].Item2, appearanceValues[i].Item2);
18921906
}
18931907
}
18941908

@@ -1988,54 +2002,59 @@ void ApplySavedTattoos()
19882002
{
19892003
List<MenuItem> items = appearanceMenu.GetMenuItems();
19902004

2005+
// Chris: This is so, so terrible... (and I wrote it)
2006+
// This needs to be re-done at some point.
2007+
// TODO: Make not trash
19912008
((MenuListItem)items[0]).ListIndex = _hairSelection;
19922009
((MenuListItem)items[1]).ListIndex = _hairColorSelection;
19932010
((MenuListItem)items[2]).ListIndex = _hairHighlightColorSelection;
19942011
((MenuListItem)items[33]).ListIndex = _eyeColorSelection;
19952012

1996-
((MenuListItem)items[3]).ListIndex = apperanceValues[0].Item1;
1997-
((MenuListItem)items[4]).ListIndex = (int)(apperanceValues[0].Item3 * 10);
2013+
((MenuListItem)items[3]).ListIndex = appearanceValues[0].Item1;
2014+
((MenuListItem)items[4]).ListIndex = (int)(appearanceValues[0].Item3 * 10);
19982015

1999-
((MenuListItem)items[5]).ListIndex = apperanceValues[1].Item1;
2000-
((MenuListItem)items[6]).ListIndex = (int)(apperanceValues[1].Item3 * 10);
2001-
((MenuListItem)items[7]).ListIndex = apperanceValues[1].Item1;
2016+
((MenuListItem)items[5]).ListIndex = appearanceValues[1].Item1;
2017+
((MenuListItem)items[6]).ListIndex = (int)(appearanceValues[1].Item3 * 10);
2018+
((MenuListItem)items[7]).ListIndex = appearanceValues[1].Item1;
20022019

2003-
((MenuListItem)items[8]).ListIndex = apperanceValues[2].Item1;
2004-
((MenuListItem)items[9]).ListIndex = (int)(apperanceValues[2].Item3 * 10);
2005-
((MenuListItem)items[10]).ListIndex = apperanceValues[2].Item1;
2020+
((MenuListItem)items[8]).ListIndex = appearanceValues[2].Item1;
2021+
((MenuListItem)items[9]).ListIndex = (int)(appearanceValues[2].Item3 * 10);
2022+
((MenuListItem)items[10]).ListIndex = appearanceValues[2].Item1;
20062023

2007-
((MenuListItem)items[11]).ListIndex = apperanceValues[3].Item1;
2008-
((MenuListItem)items[12]).ListIndex = (int)(apperanceValues[3].Item3 * 10);
2024+
((MenuListItem)items[11]).ListIndex = appearanceValues[3].Item1;
2025+
((MenuListItem)items[12]).ListIndex = (int)(appearanceValues[3].Item3 * 10);
20092026

2010-
((MenuListItem)items[13]).ListIndex = apperanceValues[4].Item1;
2011-
((MenuListItem)items[14]).ListIndex = (int)(apperanceValues[4].Item3 * 10);
2012-
((MenuListItem)items[15]).ListIndex = apperanceValues[4].Item1;
2027+
((MenuListItem)items[13]).ListIndex = appearanceValues[4].Item1;
2028+
((MenuListItem)items[14]).ListIndex = (int)(appearanceValues[4].Item3 * 10);
2029+
((MenuListItem)items[15]).ListIndex = appearanceValues[4].Item1;
20132030

2014-
((MenuListItem)items[16]).ListIndex = apperanceValues[5].Item1;
2015-
((MenuListItem)items[17]).ListIndex = (int)(apperanceValues[5].Item3 * 10);
2016-
((MenuListItem)items[18]).ListIndex = apperanceValues[5].Item1;
2031+
((MenuListItem)items[16]).ListIndex = appearanceValues[5].Item1;
2032+
((MenuListItem)items[17]).ListIndex = (int)(appearanceValues[5].Item3 * 10);
2033+
((MenuListItem)items[18]).ListIndex = appearanceValues[5].Item1;
20172034

2018-
((MenuListItem)items[19]).ListIndex = apperanceValues[6].Item1;
2019-
((MenuListItem)items[20]).ListIndex = (int)(apperanceValues[6].Item3 * 10);
2035+
((MenuListItem)items[19]).ListIndex = appearanceValues[6].Item1;
2036+
((MenuListItem)items[20]).ListIndex = (int)(appearanceValues[6].Item3 * 10);
20202037

2021-
((MenuListItem)items[21]).ListIndex = apperanceValues[7].Item1;
2022-
((MenuListItem)items[22]).ListIndex = (int)(apperanceValues[7].Item3 * 10);
2038+
((MenuListItem)items[21]).ListIndex = appearanceValues[7].Item1;
2039+
((MenuListItem)items[22]).ListIndex = (int)(appearanceValues[7].Item3 * 10);
20232040

2024-
((MenuListItem)items[23]).ListIndex = apperanceValues[8].Item1;
2025-
((MenuListItem)items[24]).ListIndex = (int)(apperanceValues[8].Item3 * 10);
2026-
((MenuListItem)items[25]).ListIndex = apperanceValues[8].Item1;
2041+
((MenuListItem)items[23]).ListIndex = appearanceValues[8].Item1;
2042+
((MenuListItem)items[24]).ListIndex = (int)(appearanceValues[8].Item3 * 10);
2043+
((MenuListItem)items[25]).ListIndex = appearanceValues[8].Item1;
20272044

2028-
((MenuListItem)items[26]).ListIndex = apperanceValues[9].Item1;
2029-
((MenuListItem)items[27]).ListIndex = (int)(apperanceValues[9].Item3 * 10);
2045+
((MenuListItem)items[26]).ListIndex = appearanceValues[9].Item1;
2046+
((MenuListItem)items[27]).ListIndex = (int)(appearanceValues[9].Item3 * 10);
20302047

2031-
((MenuListItem)items[28]).ListIndex = apperanceValues[10].Item1;
2032-
((MenuListItem)items[29]).ListIndex = (int)(apperanceValues[10].Item3 * 10);
2033-
((MenuListItem)items[30]).ListIndex = apperanceValues[10].Item1;
2048+
((MenuListItem)items[28]).ListIndex = appearanceValues[10].Item1;
2049+
((MenuListItem)items[29]).ListIndex = (int)(appearanceValues[10].Item3 * 10);
2050+
((MenuListItem)items[30]).ListIndex = appearanceValues[10].Item1;
20342051

2035-
((MenuListItem)items[31]).ListIndex = apperanceValues[11].Item1;
2036-
((MenuListItem)items[32]).ListIndex = (int)(apperanceValues[11].Item3 * 10);
2052+
((MenuListItem)items[31]).ListIndex = appearanceValues[11].Item1;
2053+
((MenuListItem)items[32]).ListIndex = (int)(appearanceValues[11].Item3 * 10);
20372054

20382055
appearanceMenu.RefreshIndex();
2056+
2057+
SetHeadBlend();
20392058
}
20402059
};
20412060

@@ -2072,9 +2091,8 @@ void ApplySavedTattoos()
20722091
ClearPedDecorations(Game.PlayerPed.Handle);
20732092
ClearPedFacialDecorations(Game.PlayerPed.Handle);
20742093
SetPedDefaultComponentVariation(Game.PlayerPed.Handle);
2075-
SetPedHairColor(Game.PlayerPed.Handle, 0, 0);
2076-
SetPedEyeColor(Game.PlayerPed.Handle, 0);
20772094
ClearAllPedProps(Game.PlayerPed.Handle);
2095+
DefaultPlayerColors();
20782096

20792097
MakeCreateCharacterMenu(male: true);
20802098
}
@@ -2108,9 +2126,8 @@ void ApplySavedTattoos()
21082126
ClearPedDecorations(Game.PlayerPed.Handle);
21092127
ClearPedFacialDecorations(Game.PlayerPed.Handle);
21102128
SetPedDefaultComponentVariation(Game.PlayerPed.Handle);
2111-
SetPedHairColor(Game.PlayerPed.Handle, 0, 0);
2112-
SetPedEyeColor(Game.PlayerPed.Handle, 0);
21132129
ClearAllPedProps(Game.PlayerPed.Handle);
2130+
DefaultPlayerColors();
21142131

21152132
MakeCreateCharacterMenu(male: false);
21162133
}
@@ -3093,6 +3110,50 @@ internal void SetPlayerClothing()
30933110
}
30943111
}
30953112

3113+
/// <summary>
3114+
/// Sets all the ped's overlay colors to their default (0) entry.
3115+
/// When called, prevents default color being bright green.
3116+
/// </summary>
3117+
internal void DefaultPlayerColors()
3118+
{
3119+
SetHeadBlend();
3120+
3121+
for (int i = 0; i < 12; i++)
3122+
{
3123+
int color = 0;
3124+
int colorIndex = 0;
3125+
3126+
switch (i)
3127+
{
3128+
case 1:
3129+
colorIndex = 1;
3130+
break;
3131+
3132+
case 2:
3133+
colorIndex = 1;
3134+
break;
3135+
3136+
case 8:
3137+
colorIndex = 2;
3138+
break;
3139+
3140+
case 10:
3141+
colorIndex = 1;
3142+
break;
3143+
3144+
default:
3145+
continue;
3146+
}
3147+
3148+
SetPedHeadOverlay(Game.PlayerPed.Handle, i, 0, 0f);
3149+
3150+
if (colorIndex > 0)
3151+
{
3152+
SetPedHeadOverlayColor(Game.PlayerPed.Handle, i, colorIndex, color, color);
3153+
}
3154+
}
3155+
}
3156+
30963157
/// <summary>
30973158
/// Create the menu if it doesn't exist, and then returns it.
30983159
/// </summary>

vMenu/menus/TimeOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void CreateMenu()
9797
if (item == freezeTimeToggle)
9898
{
9999
Subtitle.Info($"Time will now {(EventManager.IsServerTimeFrozen ? "~y~continue" : "~o~freeze")}~s~.", prefix: "Info:");
100-
UpdateServerTime(EventManager.GetServerHours, EventManager.GetServerMinutes, !EventManager.IsServerTimeFrozen);
100+
FreezeServerTime(!EventManager.IsServerTimeFrozen);
101101
}
102102
else
103103
{
@@ -117,7 +117,7 @@ private void CreateMenu()
117117
var newMinute = 0;
118118
Subtitle.Info($"Time set to ~y~{(newHour < 10 ? $"0{newHour}" : newHour.ToString())}~s~:~y~" +
119119
$"{(newMinute < 10 ? $"0{newMinute}" : newMinute.ToString())}~s~.", prefix: "Info:");
120-
UpdateServerTime(newHour, newMinute, EventManager.IsServerTimeFrozen);
120+
UpdateServerTime(newHour, newMinute);
121121
}
122122

123123
};
@@ -137,7 +137,7 @@ private void CreateMenu()
137137

138138
Subtitle.Info($"Time set to ~y~{(newHour < 10 ? $"0{newHour}" : newHour.ToString())}~s~:~y~" +
139139
$"{(newMinute < 10 ? $"0{newMinute}" : newMinute.ToString())}~s~.", prefix: "Info:");
140-
UpdateServerTime(newHour, newMinute, EventManager.IsServerTimeFrozen);
140+
UpdateServerTime(newHour, newMinute);
141141
};
142142
}
143143

vMenu/menus/VehicleOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ public void UpdateMods(int selectedIndex = 0)
19461946
SetVehicleModKit(veh.Handle, 0);
19471947

19481948
// Get all mods available on this vehicle.
1949-
var mods = veh.Mods.GetAllMods();
1949+
var mods = GetAllVehicleMods(veh);
19501950

19511951
// Loop through all the mods.
19521952
foreach (var mod in mods)

0 commit comments

Comments
 (0)