Skip to content

Instantly share code, notes, and snippets.

@DemmyDemon
Created July 23, 2023 21:31
Show Gist options
  • Save DemmyDemon/7a02309bda0e4a1540ac9d852c05b5f5 to your computer and use it in GitHub Desktop.
Save DemmyDemon/7a02309bda0e4a1540ac9d852c05b5f5 to your computer and use it in GitHub Desktop.
The question "How can I check if I'm near an ATM?" comes up a lot in FiveM scripting chat.
local maxDistance = 1.0
local IsNear = false
AddEventHandler('near-atm-distance', function(distance)
maxDistance = distance
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local coords = GetEntityCoords(PlayerPedId())
if DoesScenarioOfTypeExistInArea(coords.x, coords.y, coords.z, "PROP_HUMAN_ATM", maxDistance, false) then
if not IsNear then
TriggerEvent('near-atm', true)
IsNear = true
end
elseif IsNear then
TriggerEvent('near-atm', false)
IsNear = false
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment