Files
esx_core-esx-framework/client/main.lua
T
CyberSensei 1f2b205ea5 ATM Blips bug fixed (#29)
* blips bug fixed

fixed blips bug on map shown

* not buggy anymore
2020-07-03 18:11:50 +01:00

128 lines
2.9 KiB
Lua

-- internal variables
local hasAlreadyEnteredMarker, isInATMMarker, menuIsShowed = false, false, false
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
RegisterNetEvent('esx_atm:closeATM')
AddEventHandler('esx_atm:closeATM', function()
SetNuiFocus(false)
menuIsShowed = false
SendNUIMessage({
hideAll = true
})
end)
RegisterNUICallback('escape', function(data, cb)
TriggerEvent('esx_atm:closeATM')
cb('ok')
end)
RegisterNUICallback('deposit', function(data, cb)
TriggerServerEvent('esx_atm:deposit', data.amount)
cb('ok')
end)
RegisterNUICallback('withdraw', function(data, cb)
TriggerServerEvent('esx_atm:withdraw', data.amount)
cb('ok')
end)
-- Create blips
Citizen.CreateThread(function()
if not Config.EnableBlips then return end
for _, ATMLocation in pairs(Config.ATMLocations) do
ATMLocation.blip = AddBlipForCoord(ATMLocation.x, ATMLocation.y, ATMLocation.z - Config.ZDiff)
SetBlipSprite(ATMLocation.blip, Config.BlipSprite)
SetBlipDisplay(ATMLocation.blip, 4)
SetBlipScale(ATMLocation.blip, 0.9)
SetBlipColour(ATMLocation.blip, 2)
SetBlipAsShortRange(ATMLocation.blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('atm_blip'))
EndTextCommandSetBlipName(ATMLocation.blip)
end
end)
-- Activate menu when player is inside marker
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local coords = GetEntityCoords(PlayerPedId())
local canSleep = true
isInATMMarker = false
for k,v in pairs(Config.ATMLocations) do
if GetDistanceBetweenCoords(coords, v.x, v.y, v.z, true) < 1.0 then
isInATMMarker, canSleep = true, false
break
end
end
if isInATMMarker and not hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = true
canSleep = false
end
if not isInATMMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
SetNuiFocus(false)
menuIsShowed = false
canSleep = false
SendNUIMessage({
hideAll = true
})
end
if canSleep then
Citizen.Wait(500)
end
end
end)
-- Menu interactions
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if isInATMMarker and not menuIsShowed then
ESX.ShowHelpNotification(_U('press_e_atm'))
if IsControlJustReleased(0, 38) and IsPedOnFoot(PlayerPedId()) then
menuIsShowed = true
ESX.TriggerServerCallback('esx:getPlayerData', function(data)
SendNUIMessage({
showMenu = true,
player = {
money = data.money,
accounts = data.accounts
}
})
end)
SetNuiFocus(true, true)
end
else
Citizen.Wait(500)
end
end
end)
-- close the menu when script is stopping to avoid being stuck in NUI focus
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
if menuIsShowed then
TriggerEvent('esx_atm:closeATM')
end
end
end)