[Help] Show nearest Blip

im trying to add show nearest shop to player. i try this but not work

-- -- Create Blips
function CreateBlip(coords)
	for k,v in pairs(Config.Zones) do
		for i = 1, #v.Pos, 1 do
			local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z)
			SetBlipSprite (blip, 52)
			SetBlipDisplay(blip, 4)
			SetBlipScale  (blip, 1.0)
			SetBlipColour (blip, 2)
			SetBlipAsShortRange(blip, true)
			BeginTextCommandSetBlipName("STRING")
			AddTextComponentString(_U('shops'))
			EndTextCommandSetBlipName(blip)
		end
	end
end)
if Config.ShowNearestShopOnly then
	Citizen.CreateThread(function()
		local currentShopBlip = 0

		while true do
			Citizen.Wait(10000)

			local coords = GetEntityCoords(PlayerPedId())
			local closest = 1000
			local closestCoords

			for k,v in pairs(Config.Zones) do
				local dstcheck = GetDistanceBetweenCoords(coords, v)

				if dstcheck < closest then
					closest = dstcheck
					closestCoords = v
				end
			end

			if DoesBlipExist(currentShopBlip) then
				RemoveBlip(currentShopBlip)
			end
            
			currentShopBlip = CreateBlip(closestCoords)
		end
	end)
elseif Config.ShowAllShop then
	Citizen.CreateThread(function()
		for k,v in pairs(Config.Zones) do
			CreateBlip(v)
		end
	end)
end

i use esx_shops

I do not know if it’s right and I have no way to test it for now, but I think it would be something like this

-- -- Create Blips
function CreateBlip(coords)
	local blip = AddBlipForCoord(coords.Pos.x, coords.Pos.y, coords.Pos.z)
	SetBlipSprite (blip, 52)
	SetBlipDisplay(blip, 4)
	SetBlipScale  (blip, 1.0)
	SetBlipColour (blip, 2)
	SetBlipAsShortRange(blip, true)
	BeginTextCommandSetBlipName("STRING")
	AddTextComponentString(_U('shops'))
	EndTextCommandSetBlipName(blip)
end)
if Config.ShowNearestShopOnly then
	Citizen.CreateThread(function()
		local currentShopBlip = 0

		while true do
			Citizen.Wait(1)

			local coords = GetEntityCoords(PlayerPedId())
			local closest = 1000
			local closestCoords = {}

			for k,v in pairs(Config.Zones) do
				local dstcheck = GetDistanceBetweenCoords(coords, v.Pos)
				if dstcheck < closest then
					closest = dstcheck
					closestCoords = v
				end
			end

			if DoesBlipExist(currentShopBlip) then
				RemoveBlip(currentShopBlip)
			end
            
			currentShopBlip = CreateBlip(closestCoords)
		end
	end)
elseif Config.ShowAllShop then
	Citizen.CreateThread(function()
		for k,v in pairs(Config.Zones) do
			CreateBlip(v)
		end
	end)
end
1 Like

i cant test it now. i will reply when i test it

You tell me if it worked, and if not, tomorrow I try to take a closer look

1 Like

It not work. There something wrong