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

Commit 34fbe87

Browse files
committed
feat: Support for ox_core
TODO: - Add config option for switching ESX/OX - Add account creation logic
1 parent 7cd9ea9 commit 34fbe87

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

client.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local uiOpened = false
44
local isInBank = false
55

66
local OpenBank = function(bank)
7-
ESX.TriggerServerCallback('orp_banking:getBalance', function(balance)
7+
lib.callback('orp_banking:getBalance', 100, function(balance)
88
uiOpened = true
99
isInBank = bank == true
1010

config.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ Config.BankZones = {
7676

7777
SendNotify = function(msg, type)
7878

79-
TriggerEvent('mythic_notify:client:SendAlert', { -- https://github.com/thelindat/mythic_notify
80-
type = type,
79+
exports.ox_inventory:notify({
8180
text = msg,
82-
length = 7500
81+
type = type
8382
})
8483

85-
-- ESX.ShowNotification(msg) -- Default ESX notification
8684
-- exports['t-notify']:Alert({ style = type, message = msg }) -- https://github.com/TasoOneAsia/t-notify
8785

8886
end

fxmanifest.lua

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

99

10-
shared_script '@es_extended/imports.lua'
11-
server_script 'server.lua'
10+
shared_scripts {
11+
'@ox_core/imports.lua',
12+
'@ox_lib/init.lua'
13+
}
1214

15+
server_script 'server.lua'
1316
client_scripts {
1417
'config.lua',
1518
'client.lua'

server.lua

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,65 @@
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
46
end)
57

68

79

810
RegisterNetEvent('orp_banking:deposit', function(data)
9-
local xPlayer = ESX.GetPlayerFromId(source)
11+
local player = Player(source)
1012
local amount = tonumber(data?.amount)
1113

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')
1416
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')
1921
end
2022
end)
2123

2224
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')
2527
local amount = tonumber(data?.amount)
2628

2729
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')
2931
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')
3436
end
3537
end)
3638

3739
RegisterNetEvent('orp_banking:transfer', function(data)
38-
local xPlayer = ESX.GetPlayerFromId(source)
39-
local xTarget = ESX.GetPlayerFromId(data?.target)
4040
local amount = tonumber(data?.amount)
4141

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')
4848
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+
5053
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')
5255
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')
5659

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')
6063
end
6164
end
6265
end)

0 commit comments

Comments
 (0)