Created
July 23, 2023 21:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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