This repository was archived by the owner on Aug 30, 2023. It is now read-only.
forked from yagizher/orp-banking
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
62 lines (53 loc) · 2.75 KB
/
server.lua
File metadata and controls
62 lines (53 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
ESX.RegisterServerCallback('orp_banking:getBalance', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
cb(xPlayer and xPlayer.getAccount('bank').money or 0)
end)
RegisterNetEvent('orp_banking:deposit', function(data)
local xPlayer = ESX.GetPlayerFromId(source)
local amount = tonumber(data?.amount)
if not amount or amount <= 0 or amount > xPlayer.getMoney() then
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Invalid amount', 'error')
else
xPlayer.removeMoney(amount)
xPlayer.addAccountMoney('bank', amount)
TriggerClientEvent('orp_banking:update', xPlayer.source, xPlayer.getAccount('bank').money)
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You have successfully deposited $'.. amount, 'success')
end
end)
RegisterNetEvent('orp_banking:withdraw', function(data)
local xPlayer = ESX.GetPlayerFromId(source)
local balance = xPlayer.getAccount('bank').money
local amount = tonumber(data?.amount)
if not amount or amount <= 0 or amount > balance then
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Invalid amount', 'error')
else
xPlayer.removeAccountMoney('bank', amount)
xPlayer.addMoney(amount)
TriggerClientEvent('orp_banking:update', xPlayer.source, balance - amount)
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You have successfully withdrawn $'.. amount, 'success')
end
end)
RegisterNetEvent('orp_banking:transfer', function(data)
local xPlayer = ESX.GetPlayerFromId(source)
local xTarget = ESX.GetPlayerFromId(data?.target)
local amount = tonumber(data?.amount)
if not amount or amount <= 0 then
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Invalid amount', 'error')
elseif xTarget == nil or xTarget == -1 then
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Recipient not found', 'error')
elseif xPlayer.source == xTarget.source then
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You cannot transfer money to yourself', 'error')
else
local balance = xPlayer.getAccount('bank').money
if balance <= 0 or balance < amount or amount <= 0 then
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You don\'t have enough money for this transfer', 'error')
else
xPlayer.removeAccountMoney('bank', amount)
TriggerClientEvent('orp_banking:update', xPlayer.source, balance - amount)
TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You have successfully transferred $'.. amount, 'success')
xTarget.addAccountMoney('bank', amount)
TriggerClientEvent('orp_banking:update', xTarget.source, xTarget.getAccount('bank').money)
TriggerClientEvent('orp_banking:notify', xTarget.source, 'You just received $'.. amount ..' via bank transfer', 'success')
end
end
end)