YimMenuV2 icon indicating copy to clipboard operation
YimMenuV2 copied to clipboard

Tp to waypoint

Open ImNotKonnor opened this issue 7 months ago • 14 comments

This code attempts to improve the tracking of the different heights of the game map, thus avoiding ending up underneath it

ImNotKonnor avatar May 08 '25 17:05 ImNotKonnor

I'm kinda confused about this cause is this improved tp to waypoint or its just normal ?? Cause we already have one from the yimmenuv2 tho

rayty24 avatar May 08 '25 20:05 rayty24

Ground-Z investigation has been adjusted

  • ground_z = vec.z;
  • ground_z = vec.z + 25.f; // start slightly higher

Instead of working directly with vec.z, 25 units are now being started higher. This improves the success rate of teleporting in complex terrain.

Collision request corrected

  • STREAMING::REQUEST_COLLISION_AT_COORD (vec.x, vec.y, vec.z);
  • STREAMING::REQUEST_COLLISION_AT_COORD (vec.x, vec.y, ground_z);

Use ground_z instead of vec.z now - useful because ground_z was raised before.

Water height + safety limit

  • vec.z = water_height;
  • vec.z = std:max (water_height, min_safe_z);

Protection against too deep teleportation in the water (e.g. under the map). min_safe_z is, for example, 1.0f.

GET_GROUND_Z_FOR_3D_COORD improved

  • GET_GROUND_Z_FOR_3D_COORD (vec.x, vec.y, max_ground_check, ...)
  • GET_GROUND_Z_FOR_3D_COORD (vec.x, vec.y, ground_z, ...)

The height ground_z is used instead of a maximum fixed number - better for accuracy.

Fallback improved

  • vec.z = GET_APPROX_HEIGHT_FOR_POINT (...)
  • vec.z = std:max (GET_APPROX_HEIGHT_FOR_POINT (...), min_safe_z); Here, too, it is ensured that the height does not fall below a safe value.

SourceModzZ avatar May 08 '25 21:05 SourceModzZ

yea it will be nice to have this since the existing one sometimes tp under the ground and the car gets destroyed and some missions fail. it would be nice also to have tp to objective

xZueS19 avatar May 10 '25 17:05 xZueS19

Some places might have a ground Z value below 1. Are you sure this doesn't cause you to get teleported in the air?

maybegreat48 avatar May 17 '25 02:05 maybegreat48

make tp to object would be usefull fr

CSY0N avatar May 20 '25 12:05 CSY0N

make tp to object would be usefull fr

I'm working on a teleportation system for objects, collectibles, and objectives

ImNotKonnor avatar May 20 '25 21:05 ImNotKonnor

make tp to object would be usefull fr

I'm working on a teleportation system for objects, collectibles, and objectives

allright

CSY0N avatar May 21 '25 10:05 CSY0N

Whats with the foreign comments in the code

Tayipc38 avatar Jun 03 '25 20:06 Tayipc38

Whats with the foreign comments in the code

  1. They're using a translator to convert all code comments into English and back, or
  2. They asked a Spanish-speaking AI to make this code change for them

maybegreat48 avatar Jun 04 '25 04:06 maybegreat48

Whats with the foreign comments in the code

  1. They're using a translator to convert all code comments into English and back, or
  2. They asked a Spanish-speaking AI to make this code change for them

Neither of those options, my native language is Spanish. I simply left line 17 commented out as a reminder.

ImNotKonnor avatar Jun 05 '25 17:06 ImNotKonnor

Neither of those options, my native language is Spanish. I simply left line 17 commented out as a reminder.

Ah ok, it's just that a lot of people working on this project probably don't understand Spanish and won't be able to read your comments

Some places might have a ground Z value below 1. Are you sure this doesn't cause you to get teleported in the air?

Also, have you tested this yet?

maybegreat48 avatar Jun 07 '25 14:06 maybegreat48

Hello there,

I finally managed to build the DLL including this PR and the latest actual repo. Better than actual TP but still not perfect since it keep continuing teleporting some times under the ground at sea level and tries to go higher when there is actually nothing else.

Sometimes it happens sometime not. Build here and video if you wanna check up what I means when sea level TP and higher than ground

alzhetv avatar Jun 11 '25 22:06 alzhetv

I dont know how you can achieve this but I believe in many FiveM servers or admins menus there was a TP to Waypoint that teleports you to the lowest Z coordinate then keep raising your ped to highers Zs until you can finally stand on it.

This is what I have in mind, but this is in lua which I can more understand than c++

alzhetv avatar Jun 12 '25 13:06 alzhetv

try this code, its one from old legacy menu -

	void ResolveZCoordinate(Vector3& vec)
	{
		constexpr float max_ground_check = 1000.f;
		constexpr int max_attempts = 20;
		float ground_z = vec.z;
		int current_attempts = 0;
+		bool found_ground = false;

		do
		{
			STREAMING::REQUEST_COLLISION_AT_COORD(vec.x, vec.y, vec.z);

-			float water_height;
-			if (WATER::GET_WATER_HEIGHT(vec.x, vec.y, vec.z, &water_height))
-			{
-				vec.z = water_height;
-				return;
-			}
-
			if (MISC::GET_GROUND_Z_FOR_3D_COORD(vec.x, vec.y, max_ground_check, &ground_z, false, false))
			{
				vec.z = ground_z + 1.0f;
+				found_ground = true;
+				break;
			}

			if (current_attempts % 3 == 0)
			{
				ground_z += 25.f;
			}

			++current_attempts;
			ScriptMgr::Yield();
		} while (current_attempts < max_attempts);

+		float water_height;
+		if (WATER::GET_WATER_HEIGHT(vec.x, vec.y, vec.z, &water_height))
+		{
+			vec.z = water_height;
+			return;
+		}
		
+		if (!found_ground)
		vec.z = PATHFIND::GET_APPROX_HEIGHT_FOR_POINT(vec.x, vec.y); // fallback value
	}

lonelybud avatar Jun 14 '25 06:06 lonelybud

try this code, its one from old legacy menu -

	void ResolveZCoordinate(Vector3& vec)
	{
		constexpr float max_ground_check = 1000.f;
		constexpr int max_attempts = 20;
		float ground_z = vec.z;
		int current_attempts = 0;
+		bool found_ground = false;

		do
		{
			STREAMING::REQUEST_COLLISION_AT_COORD(vec.x, vec.y, vec.z);

-			float water_height;
-			if (WATER::GET_WATER_HEIGHT(vec.x, vec.y, vec.z, &water_height))
-			{
-				vec.z = water_height;
-				return;
-			}
-
			if (MISC::GET_GROUND_Z_FOR_3D_COORD(vec.x, vec.y, max_ground_check, &ground_z, false, false))
			{
				vec.z = ground_z + 1.0f;
+				found_ground = true;
+				break;
			}

			if (current_attempts % 3 == 0)
			{
				ground_z += 25.f;
			}

			++current_attempts;
			ScriptMgr::Yield();
		} while (current_attempts < max_attempts);

+		float water_height;
+		if (WATER::GET_WATER_HEIGHT(vec.x, vec.y, vec.z, &water_height))
+		{
+			vec.z = water_height;
+			return;
+		}
		
+		if (!found_ground)
		vec.z = PATHFIND::GET_APPROX_HEIGHT_FOR_POINT(vec.x, vec.y); // fallback value
	}

This seems to fix TPing into ground / under ground. Will needs to test more to see I encounter any issue with it.

eXhumer avatar Jun 24 '25 19:06 eXhumer

Here is a implementation i have added to Yimmenu (Legacy) a while back, little bit modified since but, works 99.9% of the time!

bool load_ground_at_3d_coordinates(Vector3& location)
{
	constexpr int max_attempts = 20;
	float ground_z = location.z;
	int current_attempts = 0;
	bool found_ground = false;
	float water_height;

	while(current_attempts < max_attempts)
	{
		constexpr float max_z = 1000.f;
		// Attempt to get ground height at the current coordinates
		found_ground = MISC::GET_GROUND_Z_FOR_3D_COORD(location.x, location.y, max_z, &ground_z, false, false);
		STREAMING::REQUEST_COLLISION_AT_COORD(location.x, location.y, location.z);

		if (found_ground)
			break;

		// Adjust z-coordinate every 3 attempts
		if (current_attempts % 3 == 0)
		{
			if (location.z < max_z)
			{
				constexpr float z_increment = 100.f;
				location.z += z_increment;
			}
			else
			{
				location.z = -200.f;
			}
		}

		++current_attempts;
		script::get_current()->yield();
	}

	if (!found_ground)
	{
		return false;
	}

	// Check for water height and adjust z-coordinate accordingly
	if (WATER::GET_WATER_HEIGHT(location.x, location.y, location.z, &water_height))
	{
		location.z = water_height;
	}
	else
	{
		location.z = ground_z;
	}

	return true;
}

EDIT-1:

After testing your code, this is what causing you to be teleported on air

vec.z = std::max(PATHFIND::GET_APPROX_HEIGHT_FOR_POINT(vec.x, vec.y), min_safe_z);

Just use the method i provided, should work well!

99Anvar99 avatar Oct 01 '25 14:10 99Anvar99