RegisterCommand('atm', function()
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed, true)
for i = 1, #Config.ATM do
local atm = GetClosestObjectOfType(playerCoords.x, playerCoords.y, playerCoords.z, 1.0, Config.ATM[i], false, false, false)
local atmPos = GetEntityCoords(atm)
local dist = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, atmPos.x, atmPos.y, atmPos.z, true)
if dist < 1.5 then
openATM()
end
end
end)
Citizen.CreateThread(function() -- Whe create a thread
while true do -- infinite loop that every 5 ms is executed
-- 38 is the control of the E button
if IsControlJustPressed(0, 38) then
ExecuteCommand("atm")
end
Citizen.Wait(5)
end
end)
The fact that âeveryone use X nativeâ doesnât mean that itâs the best option. NekixYT is right - using keymaps is a significantly âlighterâ option here and should definitely be used wherever possible.
Citizen.CreateThread(function()
while true do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local letSleep = true
for i = 1, #Config.ATM do
local atm = GetClosestObjectOfType(playerCoords.x, playerCoords.y, playerCoords.z, 1.0, Config.ATM[i], false, false, false)
local atmPos = GetEntityCoords(atm)
local dist = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, atmPos.x, atmPos.y, atmPos.z, true)
if dist < 10.0 then
letSleep = false
if dist < 1.5 then
ShowHelpText('Press ~INPUT_PICKUP~ to access to the atm')
if IsControlJustPressed(0, 38) then
openATM()
end
end
break
end
end
Citizen.Wait(letSleep and 500 or 5)
end
end)
function ShowHelpText(text)
AddTextEntry('HelpText', text)
BeginTextCommandDisplayHelp('HelpText')
EndTextCommandDisplayHelp(0, false, true, -1)
end