forked from chipsed/new_banking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
92 lines (83 loc) · 3.63 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- ================================================================================================--
-- == VARIABLES - DO NOT EDIT ==--
-- ================================================================================================--
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('bank:deposit')
AddEventHandler('bank:deposit', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if amount == nil or amount <= 0 then
TriggerClientEvent('chatMessage', _source, _U('invalid_amount'))
else
if amount > xPlayer.getMoney() then
amount = xPlayer.getMoney()
end
xPlayer.removeMoney(amount)
xPlayer.addAccountMoney('bank', tonumber(amount))
end
end)
RegisterServerEvent('bank:withdraw')
AddEventHandler('bank:withdraw', function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local base = 0
amount = tonumber(amount)
base = xPlayer.getAccount('bank').money
if amount == nil or amount <= 0 then
TriggerClientEvent('chatMessage', _source, _U('invalid_amount'))
else
if amount > base then
amount = base
end
xPlayer.removeAccountMoney('bank', amount)
xPlayer.addMoney(amount)
end
end)
RegisterServerEvent('bank:balance')
AddEventHandler('bank:balance', function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
balance = xPlayer.getAccount('bank').money
TriggerClientEvent('currentbalance1', _source, balance)
end)
RegisterServerEvent('bank:transfer')
AddEventHandler('bank:transfer', function(to, amountt)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local zPlayer = ESX.GetPlayerFromId(to)
local balance = 0
if zPlayer ~= nil then
balance = xPlayer.getAccount('bank').money
zbalance = zPlayer.getAccount('bank').money
if tonumber(_source) == tonumber(to) then
-- advanced notification with bank icon
TriggerClientEvent('esx:showAdvancedNotification', _source, 'Bank',
'Transfer Money',
'You cannot transfer to your self!',
'CHAR_BANK_MAZE', 9)
else
if balance <= 0 or balance < tonumber(amountt) or tonumber(amountt) <=
0 then
-- advanced notification with bank icon
TriggerClientEvent('esx:showAdvancedNotification', _source,
'Bank', 'Transfer Money',
'Not enough money to transfer!',
'CHAR_BANK_MAZE', 9)
else
xPlayer.removeAccountMoney('bank', tonumber(amountt))
zPlayer.addAccountMoney('bank', tonumber(amountt))
-- advanced notification with bank icon
TriggerClientEvent('esx:showAdvancedNotification', _source,
'Bank', 'Transfer Money',
'You transfered ~r~$' .. amountt ..
'~s~ to ~r~' .. to .. ' .',
'CHAR_BANK_MAZE', 9)
TriggerClientEvent('esx:showAdvancedNotification', to, 'Bank',
'Transfer Money', 'You received ~r~$' ..
amountt .. '~s~ from ~r~' .. _source ..
' .', 'CHAR_BANK_MAZE', 9)
end
end
end
end)