Hi,
I’m having trouble with my script that is trying to find the nearest ATM or Phone Booth from the player based on the hash of the object in a table.
Here is what I have:
function DisplayHelpText(str)
SetTextComponentFormat("STRING")
AddTextComponentString(str)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end
local phones = {
[1] = {"prop_phonebox_04"},
[2] = {"prop_phonebox_01a"},
[3] = {"prop_phonebox_01b"},
[4] = {"p_phonebox_02_s"},
[5] = {"p_phonebox_01b_s"},
[6] = {"prop_phonebox_03"},
[7] = {"prop_phonebox_02"},
[8] = {"prop_phonebox_01c"},
[9] = {"prop_atm_01"},
[10] = {"prop_atm_03"},
[11] = {"prop_atm_02"},
[12] = {"prop_fleeca_atm"},
}
Citizen.CreateThread(function()
while true do
local playerCoords = GetEntityCoords(GetPlayerPed(-1), true)
for i = 1, #phones do
local closestPhoneBooth = GetClosestObjectOfType(playerCoords.x, playerCoords.y, playerCoords.z, 5.0, GetHashKey(phones[i][1]), false, false, false)
if (DoesEntityExist(closestPhoneBooth)) then
local objPos = GetEntityCoords(closestPhoneBooth)
local distance = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, objPos.x, objPos.y, objPos.z, true)
if (distance <= 3) then
DisplayHelpText("Phone Booth")
else
DisplayHelpText("Nothing within radius of 3")
end
else
DisplayHelpText("Don't Exist " .. phones[i][1] .. ", " .. GetHashKey(phones[i][1]) .. ", " .. playerCoords.x .. ", " .. playerCoords.y .. ", " .. playerCoords.z)
end
end
Citizen.Wait(0)
end
end)
Its only finding the phone booth or ATM if its the last object in the table. So for example, it works if im near the fleeca ATM, but if I’m near another type of ATM (which is listed in the table), it still says its not found.
I’ve added some debugging text to the outputs and it always shows that its trying to find the last item in the list. So I know what the issue is, but not sure how to fix it.
Any ideas?