Files
esx_core/server/main.lua
T
2018-06-09 18:25:50 +02:00

38 lines
1.3 KiB
Lua

ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('esx_atm:deposit')
AddEventHandler('esx_atm:deposit', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
amount = tonumber(amount)
amount = round(amount)
if amount == nil or amount <= 0 or amount > xPlayer.getMoney() then
TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
else
xPlayer.removeMoney(amount)
xPlayer.addAccountMoney('bank', amount)
TriggerClientEvent('esx:showNotification', _source, _U('deposit_money', amount))
end
end)
RegisterServerEvent('esx_atm:withdraw')
AddEventHandler('esx_atm:withdraw', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
amount = tonumber(amount)
amount = round(amount)
local accountMoney = 0
accountMoney = xPlayer.getAccount('bank').money
if amount == nil or amount <= 0 or amount > accountMoney then
TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
else
xPlayer.removeAccountMoney('bank', amount)
xPlayer.addMoney(amount)
TriggerClientEvent('esx:showNotification', _source, _U('withdraw_money', amount))
end
end)
function round(x)
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end