47 lines
1.4 KiB
Lua
47 lines
1.4 KiB
Lua
-- client/atm_nui.lua (recommended: put callbacks in a dedicated file)
|
|
|
|
local atmToken = nil
|
|
local atmOpen = false
|
|
|
|
RegisterNetEvent("turfwar:atm:openGranted", function(token)
|
|
atmToken = token
|
|
atmOpen = true
|
|
SetNuiFocus(true, true)
|
|
SendNUIMessage({ type = "atm:open" })
|
|
end)
|
|
|
|
local function CloseATM()
|
|
atmOpen = false
|
|
atmToken = nil
|
|
SetNuiFocus(false, false)
|
|
SendNUIMessage({ type = "atm:close" })
|
|
end
|
|
|
|
RegisterNUICallback("atm:ready", function(_, cb)
|
|
-- optional: can be used if you want to delay open until UI loaded
|
|
cb({ ok = true })
|
|
end)
|
|
|
|
RegisterNUICallback("atm:close", function(_, cb)
|
|
CloseATM()
|
|
cb({ ok = true })
|
|
end)
|
|
|
|
RegisterNUICallback("atm:deposit", function(data, cb)
|
|
local amount = tonumber(data.amount) or 0
|
|
if amount <= 0 then cb({ ok = false, error = "bad_amount" }); return end
|
|
if not atmToken then cb({ ok = false, error = "no_token" }); return end
|
|
|
|
TriggerServerEvent("turfwar:finance:deposit", atmToken, amount)
|
|
cb({ ok = true })
|
|
end)
|
|
|
|
RegisterNUICallback("atm:withdraw", function(data, cb)
|
|
local amount = tonumber(data.amount) or 0
|
|
if amount <= 0 then cb({ ok = false, error = "bad_amount" }); return end
|
|
if not atmToken then cb({ ok = false, error = "no_token" }); return end
|
|
|
|
TriggerServerEvent("turfwar:finance:withdraw", atmToken, amount)
|
|
cb({ ok = true })
|
|
end)
|