Skip to content

Commit

Permalink
Fix: add small delay after setting modkit before reloading vehicle mods
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed Aug 29, 2020
1 parent 3a65b8c commit 0c642cc
Showing 1 changed file with 49 additions and 25 deletions.
74 changes: 49 additions & 25 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,33 @@ public static async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool r
// If mod info about the vehicle was specified, check if it's not null.
if (saveName != null)
{
// Set the modkit so we can modify the car.
SetVehicleModKit(vehicle.Handle, 0);
ApplyVehicleModsDelayed(vehicle, vehicleInfo, 500);
}

// Set the previous vehicle to the new vehicle.
_previousVehicle = vehicle;
//vehicle.Speed = speed; // retarded feature that randomly breaks for no fucking reason
if (!vehicle.Model.IsTrain) // to be extra fucking safe
{
// workaround of retarded feature above:
SetVehicleForwardSpeed(vehicle.Handle, speed);
}
vehicle.CurrentRPM = rpm;

// Discard the model.
SetModelAsNoLongerNeeded(vehicleHash);
}

/// <summary>
/// Waits for the given delay before applying the vehicle mods
/// </summary>
/// <param name="vehicle"></param>
/// <param name="vehicleInfo"></param>
private static async void ApplyVehicleModsDelayed(Vehicle vehicle, VehicleInfo vehicleInfo, int delay)
{
if (vehicle != null && vehicle.Exists())
{
vehicle.Mods.InstallModKit();
// set the extras
foreach (var extra in vehicleInfo.extras)
{
Expand Down Expand Up @@ -1257,35 +1281,35 @@ public static async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool r

SetVehicleWindowTint(vehicle.Handle, vehicleInfo.windowTint);

foreach (var mod in vehicleInfo.mods)
{
SetVehicleMod(vehicle.Handle, mod.Key, mod.Value, vehicleInfo.customWheels);
}
vehicle.CanTiresBurst = !vehicleInfo.bulletProofTires;

SetVehicleEnveffScale(vehicle.Handle, vehicleInfo.enveffScale);

VehicleOptions._SetHeadlightsColorOnVehicle(vehicle, vehicleInfo.headlightColor);

vehicle.Mods.NeonLightsColor = System.Drawing.Color.FromArgb(red: vehicleInfo.colors["neonR"], green: vehicleInfo.colors["neonG"], blue: vehicleInfo.colors["neonB"]);
vehicle.Mods.SetNeonLightsOn(VehicleNeonLight.Left, vehicleInfo.neonLeft);
vehicle.Mods.SetNeonLightsOn(VehicleNeonLight.Right, vehicleInfo.neonRight);
vehicle.Mods.SetNeonLightsOn(VehicleNeonLight.Front, vehicleInfo.neonFront);
vehicle.Mods.SetNeonLightsOn(VehicleNeonLight.Back, vehicleInfo.neonBack);

vehicle.CanTiresBurst = !vehicleInfo.bulletProofTires;

SetVehicleEnveffScale(vehicle.Handle, vehicleInfo.enveffScale);

VehicleOptions._SetHeadlightsColorOnVehicle(vehicle, vehicleInfo.headlightColor);
}
void DoMods()
{
vehicleInfo.mods.ToList().ForEach(mod =>
{
if (vehicle != null && vehicle.Exists())
SetVehicleMod(vehicle.Handle, mod.Key, mod.Value, vehicleInfo.customWheels);
});
}

// Set the previous vehicle to the new vehicle.
_previousVehicle = vehicle;
//vehicle.Speed = speed; // retarded feature that randomly breaks for no fucking reason
if (!vehicle.Model.IsTrain) // to be extra fucking safe
{
// workaround of retarded feature above:
SetVehicleForwardSpeed(vehicle.Handle, speed);
DoMods();
// Performance mods require a delay after setting the modkit,
// so we just do it once first so all the visual mods load instantly,
// and after a small delay we do it again to make sure all performance
// mods have also loaded.
await Delay(delay);
DoMods();
}
vehicle.CurrentRPM = rpm;

// Discard the model.
SetModelAsNoLongerNeeded(vehicleHash);
}
#endregion
#endregion
Expand Down Expand Up @@ -2517,7 +2541,7 @@ public static async Task SpawnWeaponLoadoutAsync(string saveName, bool appendWea
if (ignoreSettingsAndPerms || IsAllowed(w.Perm))
{
// Give the weapon
GiveWeaponToPed(Game.PlayerPed.Handle, w.Hash, w.CurrentAmmo > -1 ? w.CurrentAmmo: w.GetMaxAmmo, false, false);
GiveWeaponToPed(Game.PlayerPed.Handle, w.Hash, w.CurrentAmmo > -1 ? w.CurrentAmmo : w.GetMaxAmmo, false, false);

// Add components
if (w.Components.Count > 0)
Expand Down Expand Up @@ -2546,7 +2570,7 @@ public static async Task SpawnWeaponLoadoutAsync(string saveName, bool appendWea

if (w.CurrentAmmo > 0)
{
int ammo = w.CurrentAmmo;
int ammo = w.CurrentAmmo;
if (w.CurrentAmmo > w.GetMaxAmmo)
{
ammo = w.GetMaxAmmo;
Expand Down

0 comments on commit 0c642cc

Please sign in to comment.