From fa28ac9bf0557f8c0340db7286b0f9f0c158b471 Mon Sep 17 00:00:00 2001 From: Vespura <31419184+TomGrobbe@users.noreply.github.com> Date: Sun, 8 Apr 2018 21:11:06 +0200 Subject: [PATCH] Improve deleting of existing vehicles, spawning a vehicle when already inside one, and replace-previous-vehicle is disabled, it'll teleport your new car 8m straight ahead instead of spawning inside your old car. --- vMenu/CommonFunctions.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/vMenu/CommonFunctions.cs b/vMenu/CommonFunctions.cs index 4159a2d7..414371de 100644 --- a/vMenu/CommonFunctions.cs +++ b/vMenu/CommonFunctions.cs @@ -613,7 +613,7 @@ public async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool replaceP // If the previous vehicle exists... if (previousVehicle != null) { - ClearPedTasksImmediately(PlayerPedId()); + //ClearPedTasksImmediately(PlayerPedId()); // And it's actually a vehicle (rather than another random entity type) if (previousVehicle.Exists() && previousVehicle.PreviouslyOwnedByPlayer && (previousVehicle.Occupants.Count() == 0 || previousVehicle.Driver.Handle == PlayerPedId())) @@ -623,30 +623,42 @@ public async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool replaceP { // Delete it. previousVehicle.PreviouslyOwnedByPlayer = false; + SetEntityAsMissionEntity(previousVehicle.Handle, true, true); previousVehicle.Delete(); } // Otherwise else { // Set the vehicle to be no longer needed. This will make the game engine decide when it should be removed (when all players get too far away). - previousVehicle.PreviouslyOwnedByPlayer = false; previousVehicle.IsPersistent = false; previousVehicle.MarkAsNoLongerNeeded(); } previousVehicle = null; } } - if (IsPedInAnyVehicle(PlayerPedId(), false)) + + if (IsPedInAnyVehicle(PlayerPedId(), false) && (replacePrevious || !PermissionsManager.IsAllowed(Permission.VSDisableReplacePrevious))) { if (GetPedInVehicleSeat(GetVehicle(), -1) == PlayerPedId() && IsVehiclePreviouslyOwnedByPlayer(GetVehicle())) { - int tmpveh = GetVehicle(); + var tmpveh = GetVehicle(); SetVehicleHasBeenOwnedByPlayer(tmpveh, false); SetEntityAsMissionEntity(tmpveh, true, true); + + if (previousVehicle != null) + if (previousVehicle.Handle == tmpveh) + previousVehicle = null; + DeleteVehicle(ref tmpveh); } } + if (previousVehicle != null) + previousVehicle.PreviouslyOwnedByPlayer = false; + + if (IsPedInAnyVehicle(PlayerPedId(), false)) + pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0, 8f, 0.1f); + // Create the new vehicle and remove the need to hotwire the car. Vehicle vehicle = new Vehicle(CreateVehicle(vehicleHash, pos.X, pos.Y, pos.Z + 1f, heading, true, false)) { @@ -654,6 +666,10 @@ public async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool replaceP PreviouslyOwnedByPlayer = true, IsPersistent = true }; + + //// Set the previous vehicle to the new vehicle. + //previousVehicle = vehicle; + Log($"New vehicle, hash:{vehicleHash}, handle:{vehicle.Handle}, force-re-save-name:{(saveName ?? "NONE")}, created at x:{pos.X} y:{pos.Y} z:{(pos.Z + 1f)} heading:{heading}"); // If spawnInside is true