Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed NewLoadSceneStart not being stopped in the teleporting method #287

Merged
merged 3 commits into from
Mar 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,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 @@ -564,25 +567,27 @@ 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);
// Set focus for that area.
SetFocusPosAndVel(pos.X, pos.Y, pos.Z, 0, 0, 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();
// Start to load the scene.
NewLoadSceneStart(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z, 50f, 0);

// 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;
}
// Reset the timer.
tempTimer = GetGameTimer();

await Delay(0);
// Wait for the scene to be loaded with a timeout.
while (!IsNewLoadSceneLoaded() && Game.GameTime - tempTimer < 3000)
{
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();

// If the player is in a vehicle, teleport the vehicle to this new position.
if (inVehicle())
{
Expand Down