Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 30dfe3e

Browse files
committed
feat(server): Use only ox_accounts
ox_core isn't needed in this case as we only use player accounts.
1 parent 34fbe87 commit 30dfe3e

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

fxmanifest.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ description 'Banking script with qtarget support.'
77
version '2.0.0'
88

99

10-
shared_scripts {
11-
'@ox_core/imports.lua',
12-
'@ox_lib/init.lua'
13-
}
14-
10+
shared_script '@ox_lib/init.lua'
1511
server_script 'server.lua'
12+
1613
client_scripts {
1714
'config.lua',
1815
'client.lua'

server.lua

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
local inventory = exports.ox_inventory
2+
local accounts = exports.ox_accounts
23

34
lib.callback.register('orp_banking:getBalance', function(source)
4-
local player = Player(source)
5-
return player.getAccount('bank') or 0
5+
return accounts:get(source, 'bank') or 0
66
end)
77

88

99

1010
RegisterNetEvent('orp_banking:deposit', function(data)
11-
local player = Player(source)
1211
local amount = tonumber(data?.amount)
1312

1413
if not amount or amount <= 0 or amount > inventory:GetItem(source, 'money', false, true) then
1514
TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error')
1615
else
1716
inventory:RemoveItem(source, 'money', amount)
18-
player.addAccount('bank', amount)
19-
TriggerClientEvent('orp_banking:update', source, player.getAccount('bank'))
17+
accounts:add(source, 'bank', amount)
18+
TriggerClientEvent('orp_banking:update', source, accounts:get(source, 'bank'))
2019
TriggerClientEvent('orp_banking:notify', source, 'You have successfully deposited $'.. amount, 'success')
2120
end
2221
end)
2322

2423
RegisterNetEvent('orp_banking:withdraw', function(data)
25-
local player = Player(source)
26-
local balance = player.getAccount('bank')
24+
local balance = accounts:get(source, 'bank')
2725
local amount = tonumber(data?.amount)
2826

2927
if not amount or amount <= 0 or amount > balance then
3028
TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error')
3129
else
32-
player.removeAccount('bank', amount)
30+
accounts:remove(source, 'bank', amount)
3331
inventory:AddItem(source, 'money', amount)
3432
TriggerClientEvent('orp_banking:update', source, balance - amount)
3533
TriggerClientEvent('orp_banking:notify', source, 'You have successfully withdrawn $'.. amount, 'success')
@@ -46,19 +44,17 @@ RegisterNetEvent('orp_banking:transfer', function(data)
4644
elseif not amount or amount <= 0 then
4745
TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error')
4846
else
49-
local player = Player(source)
50-
local target = Player(data.target)
51-
local balance = player.getAccount('bank')
47+
local balance = accounts:get(source, 'bank')
5248

5349
if balance <= 0 or balance < amount or amount <= 0 then
5450
TriggerClientEvent('orp_banking:notify', source, 'You don\'t have enough money for this transfer', 'error')
5551
else
56-
player.removeAccount('bank', amount)
52+
accounts:remove(source, 'bank', amount)
5753
TriggerClientEvent('orp_banking:update', source, balance - amount)
5854
TriggerClientEvent('orp_banking:notify', source, 'You have successfully transferred $'.. amount, 'success')
5955

60-
target.addAccount('bank', amount)
61-
TriggerClientEvent('orp_banking:update', source, target.getAccount('bank'))
56+
accounts:add(data.target, 'bank', amount)
57+
TriggerClientEvent('orp_banking:update', source, accounts:get(data.target, 'bank'))
6258
TriggerClientEvent('orp_banking:notify', source, 'You just received $'.. amount ..' via bank transfer', 'success')
6359
end
6460
end

0 commit comments

Comments
 (0)