|
1 | | -ESX.RegisterServerCallback('orp_banking:getBalance', function(source, cb) |
2 | | - local xPlayer = ESX.GetPlayerFromId(source) |
3 | | - cb(xPlayer and xPlayer.getAccount('bank').money or 0) |
| 1 | +local inventory = exports.ox_inventory |
| 2 | + |
| 3 | +lib.callback.register('orp_banking:getBalance', function(source) |
| 4 | + local player = Player(source) |
| 5 | + return player.getAccount('bank') or 0 |
4 | 6 | end) |
5 | 7 |
|
6 | 8 |
|
7 | 9 |
|
8 | 10 | RegisterNetEvent('orp_banking:deposit', function(data) |
9 | | - local xPlayer = ESX.GetPlayerFromId(source) |
| 11 | + local player = Player(source) |
10 | 12 | local amount = tonumber(data?.amount) |
11 | 13 |
|
12 | | - if not amount or amount <= 0 or amount > xPlayer.getMoney() then |
13 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Invalid amount', 'error') |
| 14 | + if not amount or amount <= 0 or amount > inventory:GetItem(source, 'money', false, true) then |
| 15 | + TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') |
14 | 16 | else |
15 | | - xPlayer.removeMoney(amount) |
16 | | - xPlayer.addAccountMoney('bank', amount) |
17 | | - TriggerClientEvent('orp_banking:update', xPlayer.source, xPlayer.getAccount('bank').money) |
18 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You have successfully deposited $'.. amount, 'success') |
| 17 | + inventory:RemoveItem(source, 'money', amount) |
| 18 | + player.addAccount('bank', amount) |
| 19 | + TriggerClientEvent('orp_banking:update', source, player.getAccount('bank')) |
| 20 | + TriggerClientEvent('orp_banking:notify', source, 'You have successfully deposited $'.. amount, 'success') |
19 | 21 | end |
20 | 22 | end) |
21 | 23 |
|
22 | 24 | RegisterNetEvent('orp_banking:withdraw', function(data) |
23 | | - local xPlayer = ESX.GetPlayerFromId(source) |
24 | | - local balance = xPlayer.getAccount('bank').money |
| 25 | + local player = Player(source) |
| 26 | + local balance = player.getAccount('bank') |
25 | 27 | local amount = tonumber(data?.amount) |
26 | 28 |
|
27 | 29 | if not amount or amount <= 0 or amount > balance then |
28 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Invalid amount', 'error') |
| 30 | + TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') |
29 | 31 | else |
30 | | - xPlayer.removeAccountMoney('bank', amount) |
31 | | - xPlayer.addMoney(amount) |
32 | | - TriggerClientEvent('orp_banking:update', xPlayer.source, balance - amount) |
33 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You have successfully withdrawn $'.. amount, 'success') |
| 32 | + player.removeAccount('bank', amount) |
| 33 | + inventory:AddItem(source, 'money', amount) |
| 34 | + TriggerClientEvent('orp_banking:update', source, balance - amount) |
| 35 | + TriggerClientEvent('orp_banking:notify', source, 'You have successfully withdrawn $'.. amount, 'success') |
34 | 36 | end |
35 | 37 | end) |
36 | 38 |
|
37 | 39 | RegisterNetEvent('orp_banking:transfer', function(data) |
38 | | - local xPlayer = ESX.GetPlayerFromId(source) |
39 | | - local xTarget = ESX.GetPlayerFromId(data?.target) |
40 | 40 | local amount = tonumber(data?.amount) |
41 | 41 |
|
42 | | - if not amount or amount <= 0 then |
43 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Invalid amount', 'error') |
44 | | - elseif xTarget == nil or xTarget == -1 then |
45 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'Recipient not found', 'error') |
46 | | - elseif xPlayer.source == xTarget.source then |
47 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You cannot transfer money to yourself', 'error') |
| 42 | + if type(data?.target) ~= 'number' then |
| 43 | + TriggerClientEvent('orp_banking:notify', source, 'Recipient not found', 'error') |
| 44 | + elseif data?.target == source then |
| 45 | + TriggerClientEvent('orp_banking:notify', source, 'You cannot transfer money to yourself', 'error') |
| 46 | + elseif not amount or amount <= 0 then |
| 47 | + TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') |
48 | 48 | else |
49 | | - local balance = xPlayer.getAccount('bank').money |
| 49 | + local player = Player(source) |
| 50 | + local target = Player(data.target) |
| 51 | + local balance = player.getAccount('bank') |
| 52 | + |
50 | 53 | if balance <= 0 or balance < amount or amount <= 0 then |
51 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You don\'t have enough money for this transfer', 'error') |
| 54 | + TriggerClientEvent('orp_banking:notify', source, 'You don\'t have enough money for this transfer', 'error') |
52 | 55 | else |
53 | | - xPlayer.removeAccountMoney('bank', amount) |
54 | | - TriggerClientEvent('orp_banking:update', xPlayer.source, balance - amount) |
55 | | - TriggerClientEvent('orp_banking:notify', xPlayer.source, 'You have successfully transferred $'.. amount, 'success') |
| 56 | + player.removeAccount('bank', amount) |
| 57 | + TriggerClientEvent('orp_banking:update', source, balance - amount) |
| 58 | + TriggerClientEvent('orp_banking:notify', source, 'You have successfully transferred $'.. amount, 'success') |
56 | 59 |
|
57 | | - xTarget.addAccountMoney('bank', amount) |
58 | | - TriggerClientEvent('orp_banking:update', xTarget.source, xTarget.getAccount('bank').money) |
59 | | - TriggerClientEvent('orp_banking:notify', xTarget.source, 'You just received $'.. amount ..' via bank transfer', 'success') |
| 60 | + target.addAccount('bank', amount) |
| 61 | + TriggerClientEvent('orp_banking:update', source, target.getAccount('bank')) |
| 62 | + TriggerClientEvent('orp_banking:notify', source, 'You just received $'.. amount ..' via bank transfer', 'success') |
60 | 63 | end |
61 | 64 | end |
62 | 65 | end) |
0 commit comments