Get distance from marker where co-ords are in an Array

Hi All,

I need to do an IF statement to get the players distance from a array of co-ordinates.

Heres what ive got so far:

markersArray = [
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                575.40698242188,-3121.94921875,18.768627166748,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                369.9228515625,-1607.12976074219,29.291934967041,
                1848.2177734375,3689.5593261719,34.267040252686,
                -448.53857421875,6009.2690429688,31.716375350952,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                459.01037597656,-992.32800292969,30.689575195313,
                1849.7268066406,3689.9221191406,34.267040252686,
                -447.44305419922,6007.9516601563,31.716375350952,
                459.01037597656,-992.32800292969,30.689575195313
               ]

playerLocation = GetEntityCoords(GetPlayerPed(-1))

Now how would I check to see if the distance is less then say 4 meters from the co-ordinates?

Thanks
Harry

1 Like

Are you doing this in Javascript or something?

no lua

I think I’ve figured it out I’m just test now

local maxDistance = 15.0
local interactDistance = 1.2
local markersTable = {
	{ X = 459.01037597656, 	Y = -992.32800292969,  Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969,  Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969,  Z = 30.689575195313 },
	{ X = 575.40698242188, 	Y = -3121.94921875, 	 Z = 18.768627166748 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 369.9228515625, 	 Y = -1607.12976074219, Z = 29.291934967041 },
	{ X = 1848.2177734375, 	Y = 3689.5593261719,  	Z = 34.267040252686 },
	{ X = -448.53857421875,	Y = 6009.2690429688,  	Z = 31.716375350952 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 459.01037597656,  Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 },
	{ X = 1849.7268066406, 	Y = 3689.9221191406,  	Z = 34.267040252686 },
	{ X = -447.44305419922, Y = 6007.9516601563,  	Z = 31.716375350952 },
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313 }
}

Citizen.CreateThread(function()
	while true do
		local playerPos = GetEntityCoords(entity, alive)
		for k, _ in pairs(markersTable) do
			local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, markersTable[k].X, markersTable[k].Y, markersTable[k].Z)
			if distance <= maxDistance then
				--DrawMarker(type, posX, posY, posZ, dirX, dirY, dirZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ, red, green, blue, alpha, bobUpAndDown, faceCamera, p19, rotate, textureDict, textureName, drawOnEnts)
				if distance <= interactDistance then
					if IsControlJustPressed(1, 38) then -- E
						-- Do Something
					end
				end
			end
		end
		Citizen.Wait(0)
	end
end)
CreateThread(function()

    DrawMarker(0, -447.44305419922,6007.9516601563,31.716375350952, 117.14, -1950.29, 20.7513, 0, 0, 0, 1, 1, 1, 55, 255, 55, 255, 0, 0, 0, 0)
    DrawMarker(0, 1848.2177734375,3689.5593261719,34.267040252686, 117.14, -1950.29, 20.7513, 0, 0, 0, 1, 1, 1, 55, 255, 55, 255, 0, 0, 0, 0)
    DrawMarker(0, 369.9228515625,-1607.12976074219,29.291934967041, -1950.29, 20.7513, 0, 0, 0, 1, 1, 1, 55, 255, 55, 255, 0, 0, 0, 0)
    DrawMarker(0, 459.01037597656,-992.32800292969,30.689575195313, 117.14, -1950.29, 20.7513, 0, 0, 0, 1, 1, 1, 55, 255, 55, 255, 0, 0, 0, 0)
    DrawMarker(0, 575.40698242188,-3121.94921875,18.768627166748, 117.14, -1950.29, 20.7513, 0, 0, 0, 1, 1, 1, 55, 255, 55, 255, 0, 0, 0, 0)

    while true do
        Citizen.Wait(0)
            if (GetDistanceBetweenCoords(-447.44305419922,6007.9516601563,31.716375350952,GetEntityCoords(pedlol)) > 2)
                mainMenu:Visible(not mainMenu:Visible())
            elseif (GetDistanceBetweenCoords(1848.2177734375,3689.5593261719,34.267040252686,GetEntityCoords(pedlol)) > 2)
                mainMenu:Visible(not mainMenu:Visible())
            elseif (GetDistanceBetweenCoords(369.9228515625,-1607.12976074219,29.291934967041,GetEntityCoords(pedlol)) > 2)
                mainMenu:Visible(not mainMenu:Visible())
            elseif (GetDistanceBetweenCoords(459.01037597656,-992.32800292969,30.689575195313,GetEntityCoords(pedlol)) > 2)
                mainMenu:Visible(not mainMenu:Visible())
            elseif (GetDistanceBetweenCoords(575.40698242188,-3121.94921875,18.768627166748,GetEntityCoords(pedlol)) > 2)
                mainMenu:Visible(not mainMenu:Visible())
            end
    end

end)

Thats what I have

That is not correct ^ Your markers will not appear. The way I did it above will work and require less code…

wow thank you so much!

ill try it now!

If you are not sure how to call that DrawMarker native. Here is this with it fully filled out for you.

local maxDistance = 15.0
local interactDistance = 1.2
local markersTable = {
	{ X = 459.01037597656, 	Y = -992.32800292969,  Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969,  Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969,  Z = 30.689575195313},
	{ X = 575.40698242188, 	Y = -3121.94921875, 	 Z = 18.768627166748},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 369.9228515625, 	 Y = -1607.12976074219, Z = 29.291934967041},
	{ X = 1848.2177734375, 	Y = 3689.5593261719,  	Z = 34.267040252686},
	{ X = -448.53857421875,	Y = 6009.2690429688,  	Z = 31.716375350952},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 459.01037597656,  Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313},
	{ X = 1849.7268066406, 	Y = 3689.9221191406,  	Z = 34.267040252686},
	{ X = -447.44305419922, Y = 6007.9516601563,  	Z = 31.716375350952},
	{ X = 459.01037597656, 	Y = -992.32800292969, 	Z = 30.689575195313}
}

Citizen.CreateThread(function()
	while true do
		local playerPos = GetEntityCoords(entity, alive)
		for k, _ in pairs(markersTable) do
			local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, markersTable[k].X, markersTable[k].Y, markersTable[k].Z)
			if distance <= maxDistance then
				DrawMarker(1, markersTable.X, markersTable.Y, markersTable.Z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 255, 0, 0, 255, 0, 0, 0, 0, nil, nil, 0)
				if distance <= interactDistance then
					if IsControlJustPressed(1, 38) then -- E
						print("Hey.. You clicked E while next to a marker!")
					end
				end
			end
		end
		Citizen.Wait(0)
	end
end)

nvm
(twenty characters)

use the new code I pasted. It shows the correct arguments for that as your maker will be invisible and be black.

yh you put that as I replied LOL

1 Like

Doesn’t Seem to work.

I added a text notification and no markers show up.

Heres the whole thing:


local maxDistance = 15.0
local interactDistance = 2
local markersTable = {
    { X = -447.44305419922, Y = 6007.9516601563,    Z = 31.716375350952 },
    { X = -448.53857421875, Y = 6009.2690429688,    Z = 31.716375350952 },
    { X = 1848.2177734375,  Y = 3689.5593261719,    Z = 34.267040252686 },
    { X = 369.9228515625,    Y = -1607.12976074219, Z = 29.291934967041 },
    { X = 575.40698242188,  Y = -3121.94921875,      Z = 18.768627166748 }
}

Citizen.CreateThread(function()
    while true do
        local playerPos = GetEntityCoords(entity, alive)
        for k, _ in pairs(markersTable) do
            local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, markersTable[k].X, markersTable[k].Y, markersTable[k].Z)
            if distance <= maxDistance then
                DrawMarker(1, markersTable.X, markersTable.Y, markersTable.Z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 255, 0, 0, 255, 0, 0, 0, 0, nil, nil, 0)
                if distance <= interactDistance then
                    SetNotificationTextEntry("STRING")
                    AddTextComponentString("<b>Press E To Open The EUP Menu</b>") 
                    DrawNotification(true, false) 
                    if IsControlJustPressed(1, 38) then -- E
                        mainMenu:Visible(not mainMenu:Visible())
                    end
                end
            end
        end
        Citizen.Wait(0)
    end
end)

CreateThread(function()
    while true do
        Citizen.Wait(0)
        menuPool:ProcessMenus()
    end
end)

Check your client console for errors. Also why are you using ? That does not change text color or change if its bold or not on native text.

yh just removed that. Checking logs now

Hi,

I saw some errors, when you use “GetEntityCoords” what’s “entity” and “alive”? theses variables don’t seem to exist. Then, when you what to draw a marker with “DrawMarker”, you use “markersTable.X” and juste above “markersTable[k].X”. It’s a table of objects, so you have to specify an index every time.

You can try with this code:

local maxDistance = 15.0
local interactDistance = 2
local markersTable = {
    { X = -447.44305419922, Y = 6007.9516601563,    Z = 31.716375350952 },
    { X = -448.53857421875, Y = 6009.2690429688,    Z = 31.716375350952 },
    { X = 1848.2177734375,  Y = 3689.5593261719,    Z = 34.267040252686 },
    { X = 369.9228515625,    Y = -1607.12976074219, Z = 29.291934967041 },
    { X = 575.40698242188,  Y = -3121.94921875,      Z = 18.768627166748 }
}

Citizen.CreateThread(function()
    while true do
        local playerPos = GetEntityCoords(GetPlayerPed(-1), true)
        for k, _ in pairs(markersTable) do
            local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, markersTable[k].X, markersTable[k].Y, markersTable[k].Z)
            if distance <= maxDistance then
                DrawMarker(1, markersTable[k].X, markersTable[k].Y, markersTable[k].Z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 255, 0, 0, 255, 0, 0, 0, 0, nil, nil, 0)
                if distance <= interactDistance then
                    SetNotificationTextEntry("STRING")
                    AddTextComponentString("<b>Press E To Open The EUP Menu</b>") 
                    DrawNotification(true, false) 
                    if IsControlJustPressed(1, 38) then -- E
                        mainMenu:Visible(not mainMenu:Visible())
                    end
                end
            end
        end
        Citizen.Wait(0)
    end
end)

CreateThread(function()
    while true do
        Citizen.Wait(0)
        menuPool:ProcessMenus()
    end
end)

Nope doesn’t seem to work

heres a ghostbin:

https://ghostbin.com/paste/jk9m2

bump @fauconjona @xander1998

still doesn’t work x

I’ll test it in few hours, to debug where it’s broken.

Is there the notification or nothing happen?

no notification or anything. Very weird

Any results @fauconjona?

I tried separating the co-ords but it doesn’t seem to detect it.

Citizen.CreateThread(function()

    local ply = GetPlayerPed(-1)
    local plyCoords = GetEntityCoords(ply, 0)
	local distance = GetDistanceBetweenCoords(-447.4,6007.950,31.7,  plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
	while true do
	    if(distance <= 5) then
	        SetNotificationTextEntry("STRING")
       		AddTextComponentString("Press E To Open The EUP Menu") 
        	DrawNotification(true, false) 
        	if IsControlJustPressed(1, 38) then -- E
           		mainMenu:Visible(not mainMenu:Visible())
        	end
	    end
     	Citizen.Wait(0)
	end
	print("EUP Client Trigger Created")
end)

Still no luck