|
1 | | -local inventory = exports.ox_inventory |
2 | | -local accounts = exports.ox_accounts |
| 1 | +local ox_inventory = exports.ox_inventory |
3 | 2 |
|
4 | 3 | lib.callback.register('orp_banking:getBalance', function(source) |
5 | | - return accounts:get(source, 'bank') or 0 |
| 4 | + local accounts = Ox.GetPlayer(source).getAccounts() |
| 5 | + return accounts.get('bank') or 0 |
6 | 6 | end) |
7 | 7 |
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | RegisterNetEvent('orp_banking:deposit', function(data) |
11 | 11 | local amount = tonumber(data?.amount) |
12 | 12 |
|
13 | | - if not amount or amount <= 0 or amount > inventory:GetItem(source, 'money', false, true) then |
14 | | - TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') |
| 13 | + if not amount or amount <= 0 or amount > ox_inventory:GetItem(source, 'money', nil, true) then |
| 14 | + TriggerClientEvent('ox_lib:notify', source, { |
| 15 | + type = 'error', |
| 16 | + description = 'Invalid amount' |
| 17 | + }) |
15 | 18 | else |
16 | | - inventory:RemoveItem(source, 'money', amount) |
17 | | - accounts:add(source, 'bank', amount) |
18 | | - TriggerClientEvent('orp_banking:update', source, accounts:get(source, 'bank')) |
19 | | - TriggerClientEvent('orp_banking:notify', source, 'You have successfully deposited $'.. amount, 'success') |
| 19 | + local accounts = Ox.GetPlayer(source).getAccounts() |
| 20 | + accounts.add('bank', amount) |
| 21 | + ox_inventory:RemoveItem(source, 'money', amount) |
| 22 | + |
| 23 | + TriggerClientEvent('orp_banking:update', source, accounts.get('bank')) |
| 24 | + TriggerClientEvent('ox_lib:notify', source, { |
| 25 | + type = 'success', |
| 26 | + description = 'You have successfully deposited $'.. amount |
| 27 | + }) |
20 | 28 | end |
21 | 29 | end) |
22 | 30 |
|
23 | 31 | RegisterNetEvent('orp_banking:withdraw', function(data) |
24 | | - local balance = accounts:get(source, 'bank') |
| 32 | + local accounts = Ox.GetPlayer(source).getAccounts() |
| 33 | + local balance = accounts.get('bank') |
25 | 34 | local amount = tonumber(data?.amount) |
26 | 35 |
|
27 | 36 | if not amount or amount <= 0 or amount > balance then |
28 | | - TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') |
| 37 | + TriggerClientEvent('ox_lib:notify', source, { |
| 38 | + type = 'error', |
| 39 | + description = 'Invalid amount' |
| 40 | + }) |
29 | 41 | else |
30 | | - accounts:remove(source, 'bank', amount) |
31 | | - inventory:AddItem(source, 'money', amount) |
| 42 | + accounts.remove('bank', amount) |
| 43 | + ox_inventory:AddItem(source, 'money', amount) |
| 44 | + |
32 | 45 | TriggerClientEvent('orp_banking:update', source, balance - amount) |
33 | | - TriggerClientEvent('orp_banking:notify', source, 'You have successfully withdrawn $'.. amount, 'success') |
| 46 | + TriggerClientEvent('ox_lib:notify', source, { |
| 47 | + type = 'success', |
| 48 | + description = 'You have successfully withdrawn $'.. amount |
| 49 | + }) |
34 | 50 | end |
35 | 51 | end) |
36 | 52 |
|
37 | 53 | RegisterNetEvent('orp_banking:transfer', function(data) |
38 | 54 | local amount = tonumber(data?.amount) |
39 | 55 |
|
40 | 56 | if type(data?.target) ~= 'number' then |
41 | | - TriggerClientEvent('orp_banking:notify', source, 'Recipient not found', 'error') |
| 57 | + TriggerClientEvent('ox_lib:notify', source, { |
| 58 | + type = 'error', |
| 59 | + description = 'Recipient not found' |
| 60 | + }) |
42 | 61 | elseif data?.target == source then |
43 | | - TriggerClientEvent('orp_banking:notify', source, 'You cannot transfer money to yourself', 'error') |
| 62 | + TriggerClientEvent('ox_lib:notify', source, { |
| 63 | + type = 'error', |
| 64 | + description = 'You cannot transfer money to yourself' |
| 65 | + }) |
44 | 66 | elseif not amount or amount <= 0 then |
45 | | - TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') |
| 67 | + TriggerClientEvent('ox_lib:notify', source, { |
| 68 | + type = 'error', |
| 69 | + description = 'Invalid amount' |
| 70 | + }) |
46 | 71 | else |
47 | | - local balance = accounts:get(source, 'bank') |
| 72 | + local accounts = Ox.GetPlayer(source).getAccounts() |
| 73 | + local balance = accounts.get('bank') |
48 | 74 |
|
49 | 75 | if balance <= 0 or balance < amount or amount <= 0 then |
50 | | - TriggerClientEvent('orp_banking:notify', source, 'You don\'t have enough money for this transfer', 'error') |
| 76 | + TriggerClientEvent('ox_lib:notify', source, { |
| 77 | + type = 'error', |
| 78 | + description = 'You don\'t have enough money for this transfer' |
| 79 | + }) |
51 | 80 | else |
52 | | - accounts:remove(source, 'bank', amount) |
| 81 | + accounts.remove('bank', amount) |
53 | 82 | TriggerClientEvent('orp_banking:update', source, balance - amount) |
54 | | - TriggerClientEvent('orp_banking:notify', source, 'You have successfully transferred $'.. amount, 'success') |
| 83 | + TriggerClientEvent('ox_lib:notify', source, { |
| 84 | + type = 'success', |
| 85 | + description = 'You have successfully transferred $'.. amount |
| 86 | + }) |
55 | 87 |
|
56 | | - accounts:add(data.target, 'bank', amount) |
57 | | - TriggerClientEvent('orp_banking:update', source, accounts:get(data.target, 'bank')) |
58 | | - TriggerClientEvent('orp_banking:notify', source, 'You just received $'.. amount ..' via bank transfer', 'success') |
| 88 | + local target = Ox.GetPlayer(data.target).getAccounts() |
| 89 | + target.add('bank', amount) |
| 90 | + TriggerClientEvent('orp_banking:update', source, target.get('bank')) |
| 91 | + TriggerClientEvent('ox_lib:notify', source, { |
| 92 | + type = 'success', |
| 93 | + description = 'You just received $'.. amount ..' via bank transfer' |
| 94 | + }) |
59 | 95 | end |
60 | 96 | end |
61 | 97 | end) |
0 commit comments