Coords for teleporting behave weirdly...? Pixel painting included!

Hi!

I’ve wanted to create teleport option in personal menu for addon map in the skies. It should be an option only for people who are already got there via different teleport.

This teleporting feature inside this giant map is working, BUT when I want to set distance in which they can still use this teleport to start line, it behaves very weirdly. When I was using sphere as graphic marker for certain distance across this map, it looked very easy. But actual distance that enables the teleport from ESX menu doesn’t behave the same way. Upon using noclip, the allowed area for this teleport have been eg. 4000 units into northern direction, NW maybe around 500 and W about 3-4000 again.

Maybe I am doing something (again) wrong, but I though it will “GetDistanceBetweenCoords” native will behave same in all directions

function openpersonalmenu()

local plyCoords = GetEntityCoords(PlayerPedId())		
local RingArea = 4381.696, -4250.229, 2102.323		--	same "non-spherical" problem
local RingArea1 = 3719.256, -2689.689, 2970.752
local RingArea2 = 6139.038, -3346.716, 2123.272
local RingArea3 = 3204.921, -6455.424, 2213.802
local RingArea4 = 2352.362, -5078.228, 2188.063

local IsInRingArea = GetDistanceBetweenCoords(plyCoords, RingArea, true)
local IsInRingArea1 = GetDistanceBetweenCoords(plyCoords, RingArea1, true)
local IsInRingArea2 = GetDistanceBetweenCoords(plyCoords, RingArea2, true)
local IsInRingArea3 = GetDistanceBetweenCoords(plyCoords, RingArea3, true)
local IsInRingArea4 = GetDistanceBetweenCoords(plyCoords, RingArea4, true)
local elements = {
	{label = _U('id_card'), value = 'id_kort'},
		{label = _U('bills'), value = 'bills'},	
		{label = _U('OpenAnimationsMenu'), value = 'OpenAnimationsMenu'}}
		
	if 	(IsInRingArea1 <= 3000.0) or (IsInRingArea2 <= 3000.0) or (IsInRingArea3 <= 3000.0) or (IsInRingArea4 <= 3000.0) then
		table.insert(elements, {label = _U('RingAreaMenu'), value = 'RingAreaMenu'})
	end



  ESX.UI.Menu.CloseAll()

  ESX.UI.Menu.Open(
    'default', GetCurrentResourceName(), 'personal_menu',
    { title    = _U('personal_menu'),
      align    = 'left',
      elements = elements	 
    },
		function(data, menu)
		if data.current.value == 'id_kort' then
			openMenu()
		end
		if data.current.value == 'RingAreaMenu' then
			RingAreaTp()
		end			
	   		
	  end,
        function(data, menu)
          menu.close()
          OpenCivilianActionsMenu()
    end
	)
end

function RingAreaTp()

local targetPed = PlayerPedId()

	if	(IsPedInAnyVehicle(targetPed)) then
		targetPed = GetVehiclePedIsUsing(targetPed)
        DoScreenFadeOut(100)
        Citizen.Wait(750)
        SetEntityCoordsNoOffset(targetPed, 3537.103, -6537.880, 2188.207, 0, 0, 1)
		FreezeEntityPosition(targetPed, true)	--	prevention for falling though texture 
		Citizen.Wait(250)
		FreezeEntityPosition(targetPed, false)
        DoScreenFadeIn(100)
    end
end

Bit of visual explanation, where words might have failed

if 	(IsInRingArea1 <= 3000.0) or (IsInRingArea2 <= 3000.0) or (IsInRingArea3 <= 3000.0) or (IsInRingArea4 <= 3000.0) then
	table.insert(elements, {label = _U('RingAreaMenu'), value = 'RingAreaMenu'})
end

So if the player is near the Area1, you want him to be able to access the RingAreaMenu?
First I do not understand this… I would suggest you to differ the 4 destination:

if (IsInRingArea1 <= 3000.0) then
    table.insert(elements, {label = _U('RingAreaMenu1'), value = 'RingAreaMenu1'})
end
if (IsInRingArea2 <= 3000.0) then
    table.insert(elements, {label = _U('RingAreaMenu2'), value = 'RingAreaMenu2'})
end
if (IsInRingArea3 <= 3000.0) then
    table.insert(elements, {label = _U('RingAreaMenu3'), value = 'RingAreaMenu3'})
end
if (IsInRingArea4 <= 3000.0) then
    table.insert(elements, {label = _U('RingAreaMenu4'), value = 'RingAreaMenu4'})
end

Why is it always the same destination?

SetEntityCoordsNoOffset(targetPed, 3537.103, -6537.880, 2188.207, 0, 0, 1)

EDIT:

targetPed = GetVehiclePedIsUsing(targetPed)

What the fuck?

EDIT2: I changed your code, so it looks better than declaring 1000 variables: https://hastebin.com/mebosacoha.php

Well, first I’ve tried to get it done just by distance between player and one central point (aka big area/sphere) hovering over the city. That didn’t go well, so I’ve tried few little ones. Same stupid result. Doesn’t work how I need it to. I need check of distance in every direction.

The same destination is near start line, so players who will crash on the track can port easily back, as they don’t use any trainers.

targetPed = GetVehiclePedIsUsing(targetPed)

is just check, if ped is sitting in vehicle, so the teleport will include car as well. That works as intended.

Thank you for your edit, I will try it tomorrow!

Ok, Could you please write what are you expecting from your code? I really didn’t understand the purpose ^^’