MenyooSP icon indicating copy to clipboard operation
MenyooSP copied to clipboard

Teleport to Waypoint not working (possible solution)

Open ShawnPR1 opened this issue 3 years ago • 0 comments

When teleporting to your waypoint (when it has been placed somewhere like on Mt. Chiliad) you simply fall below the map. Likely due to height of the blipCoord not really working as expected.

I'm struggling to properly create a pull request so I'll simply post a possible fix (along with some minor refactoring that's probably quite horrid but still) in this post for anyone that can please create a pull request with these changes (after testing).

In this namespace: 'namespace sub::TeleportLocations_catind » namespace TeleMethods' I suggest adjusting the ToWaypoint method as follows:

void ToWaypoint(GTAped ped)
{
	if (IS_WAYPOINT_ACTIVE())
	{
		static float ____gtaGroundCheckHeight[] = {
    		        100.0, 150.0, 50.0, 0.0, 200.0, 250.0, 300.0, 350.0, 400.0,
			450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0
		};

		Vector3& blipCoords = GTAblip(GET_FIRST_BLIP_INFO_ID(BlipIcon::Waypoint)).Position_get();

		GTAentity e = ped;
		if (ped.IsInVehicle())
			e = ped.CurrentVehicle();

		GET_GROUND_Z_FOR_3D_COORD(blipCoords.x, blipCoords.y, 810.0, &blipCoords.z);

		Game::RequestControlOfId(e.NetID());
		e.RequestControl(1000);

		for (int height : ____gtaGroundCheckHeight)
		{
			SET_ENTITY_COORDS_NO_OFFSET(e.Handle(), blipCoords.x, blipCoords.y, height, 0, 0, 1);
			WAIT(100);
			if (GET_GROUND_Z_FOR_3D_COORD(blipCoords.x, blipCoords.y, height, &blipCoords.z))
				break;
		}
		SET_ENTITY_COORDS_NO_OFFSET(e.Handle(), blipCoords.x, blipCoords.y, blipCoords.z, 0, 0, 1);
	}
	else {
		Game::Print::PrintBottomCentre("~r~Error:~s~ No Waypoint set.");
	}
}

Changes I've applied:

  • Added 850.0 to the ____gtaGroundCheckHeight array
  • Adjusted the first GET_GROUND_Z_FOR_3D_COORD call to use the max height of 810 (doesn't make much of a difference tbh)
  • Used SET_ENTITY_COORDS_NO_OFFSET instead of SET_ENTITY_COORDS (not sure if this helps fix the issue tbh)
  • Instead of having 2 if statements for if the player is in a vehicle, with the same code within the else statement basically, I changed the main teleport target entity in a single if statement
  • Changed the teleport call to teleport the entity (vehicle or player) to the current ____gtaGroundCheckHeight in the for (height) instead of using blipCoords.z (I believe this is the major reason it seems that fixes the issue)

Hope this code is acceptable. Also not even sure if anyone else is having this same issue with teleporting to waypoint.

ShawnPR1 avatar Mar 23 '22 21:03 ShawnPR1