-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
70 lines (62 loc) · 2.6 KB
/
server.lua
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
63
64
65
66
67
68
69
70
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('orp:bank:deposit')
AddEventHandler('orp:bank:deposit', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if amount == nil or amount <= 0 or amount > xPlayer.getMoney() then
TriggerClientEvent('orp:bank:notify', _source, "error", "Invalid Amount")
else
xPlayer.removeMoney(amount)
xPlayer.addAccountMoney('bank', tonumber(amount))
TriggerClientEvent('orp:bank:notify', _source, "success", "You successfully deposit $" .. amount)
end
end)
RegisterServerEvent('orp:bank:withdraw')
AddEventHandler('orp:bank:withdraw', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local min = 0
amount = tonumber(amount)
min = xPlayer.getAccount('bank').money
if amount == nil or amount <= 0 or amount > min then
TriggerClientEvent('orp:bank:notify', _source, "error", "Invalid Amount")
else
xPlayer.removeAccountMoney('bank', amount)
xPlayer.addMoney(amount)
TriggerClientEvent('orp:bank:notify', _source, "success", "You successfully withdraw $" .. amount)
end
end)
RegisterServerEvent('orp:bank:balance')
AddEventHandler('orp:bank:balance', function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
balance = xPlayer.getAccount('bank').money
TriggerClientEvent('orp:bank:info', _source, balance)
end)
RegisterServerEvent('orp:bank:transfer')
AddEventHandler('orp:bank:transfer', function(to, amountt)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local xTarget = ESX.GetPlayerFromId(to)
local amount = amountt
local balance = 0
if(xTarget == nil or xTarget == -1) then
TriggerClientEvent('orp:bank:notify', _source, "error", "Recipient not found")
else
balance = xPlayer.getAccount('bank').money
zbalance = xTarget.getAccount('bank').money
if tonumber(_source) == tonumber(to) then
TriggerClientEvent('orp:bank:notify', _source, "error", "You cannot transfer money to yourself")
else
if balance <= 0 or balance < tonumber(amount) or tonumber(amount) <= 0 then
TriggerClientEvent('orp:bank:notify', _source, "error", "You don't have enough money for this transfer")
else
xPlayer.removeAccountMoney('bank', tonumber(amount))
xTarget.addAccountMoney('bank', tonumber(amount))
TriggerClientEvent('orp:bank:notify', _source, "success", "You successfully transfer $" .. amount)
TriggerClientEvent('orp:bank:notify', to, "success", "You have just received $" .. amount .. ' via transfer')
end
end
end
end)