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

Commit cbeb94d

Browse files
committed
refactor: Use ox_lib and ox_core accounts
1 parent 30dfe3e commit cbeb94d

File tree

4 files changed

+76
-42
lines changed

4 files changed

+76
-42
lines changed

client.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ local OpenBank = function(bank)
1616
})
1717

1818
if not isInBank then
19-
SendNotify('Please note that you can only deposit money at bank', 'inform')
19+
lib.notify({
20+
type = 'inform',
21+
description = 'Please note that you can only deposit money at bank'
22+
})
2023
end
2124
end)
2225
end
@@ -26,9 +29,10 @@ local CloseBank = function()
2629
SetNuiFocus(false, false)
2730
end
2831

29-
local currentResource = GetCurrentResourceName()
3032
AddEventHandler('onResourceStop', function(resource)
31-
if resource == currentResource then CloseBank() end
33+
if resource == cache.resource then
34+
CloseBank()
35+
end
3236
end)
3337

3438

@@ -49,7 +53,10 @@ RegisterNUICallback('deposit', function(data)
4953
if isInBank then
5054
TriggerServerEvent('orp_banking:deposit', data)
5155
else
52-
SendNotify('You cannot deposit money at an ATM', 'error')
56+
lib.notify({
57+
type = 'error',
58+
description = 'You cannot deposit money at an ATM'
59+
})
5360
end
5461
end)
5562

config.lua

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,3 @@ Config.BankZones = {
7373
maxZ = 33.12
7474
}
7575
}
76-
77-
SendNotify = function(msg, type)
78-
79-
exports.ox_inventory:notify({
80-
text = msg,
81-
type = type
82-
})
83-
84-
-- exports['t-notify']:Alert({ style = type, message = msg }) -- https://github.com/TasoOneAsia/t-notify
85-
86-
end
87-
88-
RegisterNetEvent('orp_banking:notify', SendNotify)

fxmanifest.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ version '2.0.0'
88

99

1010
shared_script '@ox_lib/init.lua'
11-
server_script 'server.lua'
11+
12+
server_scripts {
13+
'@ox_core/imports/server.lua',
14+
'server.lua'
15+
}
1216

1317
client_scripts {
1418
'config.lua',

server.lua

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,97 @@
1-
local inventory = exports.ox_inventory
2-
local accounts = exports.ox_accounts
1+
local ox_inventory = exports.ox_inventory
32

43
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
66
end)
77

88

99

1010
RegisterNetEvent('orp_banking:deposit', function(data)
1111
local amount = tonumber(data?.amount)
1212

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+
})
1518
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+
})
2028
end
2129
end)
2230

2331
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')
2534
local amount = tonumber(data?.amount)
2635

2736
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+
})
2941
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+
3245
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+
})
3450
end
3551
end)
3652

3753
RegisterNetEvent('orp_banking:transfer', function(data)
3854
local amount = tonumber(data?.amount)
3955

4056
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+
})
4261
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+
})
4466
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+
})
4671
else
47-
local balance = accounts:get(source, 'bank')
72+
local accounts = Ox.GetPlayer(source).getAccounts()
73+
local balance = accounts.get('bank')
4874

4975
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+
})
5180
else
52-
accounts:remove(source, 'bank', amount)
81+
accounts.remove('bank', amount)
5382
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+
})
5587

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+
})
5995
end
6096
end
6197
end)

0 commit comments

Comments
 (0)