Skip to content

Commit

Permalink
Fixed NewLoadSceneStart not being stopped in the teleporting method
Browse files Browse the repository at this point in the history
This was causing texture loss in the city when using the teleport to waypoint option or teleport to player option (which both were using the safe teleport option).
  • Loading branch information
QuadrupleTurbo committed Mar 3, 2023
1 parent 0b1fae1 commit cdad06f
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ public static async Task TeleportToCoords(Vector3 pos, bool safeModeDisabled = f
await Delay(0);
}

// Timer to make sure things don't get out of hand (player having to wait forever to get teleported if something fails).
int tempTimer;

// This will be used to get the return value from the groundz native.
float groundZ = 850.0f;

Expand All @@ -561,25 +564,6 @@ public static async Task TeleportToCoords(Vector3 pos, bool safeModeDisabled = f
// it seem to load the world ANY faster than without, but whatever.
RequestCollisionAtCoord(pos.X, pos.Y, z);

// Request a new scene. This will trigger the world to be loaded around that area.
NewLoadSceneStart(pos.X, pos.Y, z, pos.X, pos.Y, z, 50f, 0);

// Timer to make sure things don't get out of hand (player having to wait forever to get teleported if something fails).
int tempTimer = GetGameTimer();

// Wait for the new scene to be loaded.
while (IsNetworkLoadingScene())
{
// If this takes longer than 1 second, just abort. It's not worth waiting that long.
if (GetGameTimer() - tempTimer > 1000)
{
Log("Waiting for the scene to load is taking too long (more than 1s). Breaking from wait loop.");
break;
}

await Delay(0);
}

// If the player is in a vehicle, teleport the vehicle to this new position.
if (inVehicle())
{
Expand Down Expand Up @@ -680,6 +664,27 @@ public static async Task TeleportToCoords(Vector3 pos, bool safeModeDisabled = f
Game.PlayerPed.IsPositionFrozen = false;
}

// Set focus for that area.
SetFocusPosAndVel(pos.X, pos.Y, pos.Z, 0, 0, 0);

// Start to load the scene.
NewLoadSceneStart(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z, 50f, 0);

// Reset the timer.
tempTimer = GetGameTimer();

// Wait for the scene to be loaded with a timeout.
while (!IsNewLoadSceneLoaded() && Game.GameTime - tempTimer < 10000) // Can take up to 10 seconds
{
await BaseScript.Delay(0);
}

// Clear the focus for that area.
ClearFocus();

// Important! This step was missing before, not setting this would cause areas outside the scene to become unrendered aka "city mud" would appear.
NewLoadSceneStop();

// Fade screen in and reset the camera angle.
DoScreenFadeIn(500);
SetGameplayCamRelativePitch(0.0f, 1.0f);
Expand Down

0 comments on commit cdad06f

Please sign in to comment.