[ HELP ] Teleport to waypoint command doesn't work on longer distances

Hello! I’ve created a script which like any normal /tpm script. Although there is 1 mini problem, it doesn’t work on longer distances. here’s the script:

RegisterCommand( "tpm", function() 
    local waypointHandle = GetFirstBlipInfoId( 8 )
    local ped = GetPlayerPed( -1 )
    local blipCoords = GetBlipCoords( waypointHandle )

    if DoesBlipExist( waypointHandle ) then
        for height = 1, 1000 do
            local foundGround = GetGroundZFor_3dCoord( blipCoords.x, blipCoords.y, height + 0.0 )
            
            if foundGround then
                SetEntityCoords( ped, blipCoords.x, blipCoords.y, height + 0.0, false, false, false, false )
                break
            end
        end
    else
        TriggerEvent( "aq:notify", "~y~Place a waypoint." )
    end
    print( blipCoords )
end)

Hoping to get an answer!

1 Like

Hi there! As I’ve added to the native reference, this native doesn’t work on long distances (since it can only calculate the coordinates if the terrain is within the client’s render distance). You’ll need to teleport the player to the area first, then check for the ground elevation.

Learning something new with markers, will check on if I can manage to fix it myself, thanks! <3.

So I tried something like this:

RegisterCommand( "tpm", function() 
    local waypointHandle = GetFirstBlipInfoId( 8 )

    if DoesBlipExist( waypointHandle ) then
        local blipCoords = GetBlipInfoIdCoord( waypointHandle )

        for height = 1, 1000 do
            SetEntityCoords( GetPlayerPed( -1 ), blipCoords[ "x" ], blipCoords[ "y" ], height + 0.0, false, false, false, false )

            local foundGround = GetGroundZFor_3dCoord( blipCoords[ "x" ], blipCoords[ "y" ], height + 0.0 )
            
            if foundGround then
                SetEntityCoords( GetPlayerPed( -1 ), blipCoords[ "x" ], blipCoords[ "y" ], height + 0.0, false, false, false, false )
                break
            end
        end

        print( blipCoords )
        TriggerEvent( "aq:getCoords" )
    else
        TriggerEvent( "aq:notify", "~y~Place a waypoint." )
    end
end)

But now, instead of not teleporting, I teleport above the sky.

RegisterCommand( "tpm", function() 
    local waypointHandle = GetFirstBlipInfoId( 8 )

    if DoesBlipExist( waypointHandle ) then
        local blipCoords = GetBlipInfoIdCoord( waypointHandle )
 incr=0
 DoScreenFadeOut(100)
 CreateThread(function()
	while incr<1000 do
		Wait(1) 
		incr=incr+1
			
			SetEntityCoords( GetPlayerPed( -1 ), blipCoords.x, blipCoords.y, incr*1.0, 0.0, 0.0, 0.0, false )
            
            foundGround,g = GetGroundZFor_3dCoord(blipCoords.x, blipCoords.y, incr*1.0)
            
            if foundGround then
				print(g)
                SetEntityCoords( GetPlayerPed( -1 ), blipCoords.x, blipCoords.y,g*1.0, 0.0, 0.0, 0.0, false )
				DoScreenFadeIn(500)
                break
            end
			
		end
    end)
	if incr>900 then
		DoScreenFadeIn(500)
		--just in case
	end
      --  print( blipCoords )
       -- TriggerEvent( "aq:getCoords" )
    else
	 print('Place a waypoint')
        --TriggerEvent( "aq:notify", "~y~Place a waypoint." )
    end
end)

the higher the waypoint the more you wait but its like max 2-3 secs