This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
forked from yagizher/orp-banking
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use ox_lib and ox_core accounts
- Loading branch information
Showing
4 changed files
with
76 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,97 @@ | ||
local inventory = exports.ox_inventory | ||
local accounts = exports.ox_accounts | ||
local ox_inventory = exports.ox_inventory | ||
|
||
lib.callback.register('orp_banking:getBalance', function(source) | ||
return accounts:get(source, 'bank') or 0 | ||
local accounts = Ox.GetPlayer(source).getAccounts() | ||
return accounts.get('bank') or 0 | ||
end) | ||
|
||
|
||
|
||
RegisterNetEvent('orp_banking:deposit', function(data) | ||
local amount = tonumber(data?.amount) | ||
|
||
if not amount or amount <= 0 or amount > inventory:GetItem(source, 'money', false, true) then | ||
TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') | ||
if not amount or amount <= 0 or amount > ox_inventory:GetItem(source, 'money', nil, true) then | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'error', | ||
description = 'Invalid amount' | ||
}) | ||
else | ||
inventory:RemoveItem(source, 'money', amount) | ||
accounts:add(source, 'bank', amount) | ||
TriggerClientEvent('orp_banking:update', source, accounts:get(source, 'bank')) | ||
TriggerClientEvent('orp_banking:notify', source, 'You have successfully deposited $'.. amount, 'success') | ||
local accounts = Ox.GetPlayer(source).getAccounts() | ||
accounts.add('bank', amount) | ||
ox_inventory:RemoveItem(source, 'money', amount) | ||
|
||
TriggerClientEvent('orp_banking:update', source, accounts.get('bank')) | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'success', | ||
description = 'You have successfully deposited $'.. amount | ||
}) | ||
end | ||
end) | ||
|
||
RegisterNetEvent('orp_banking:withdraw', function(data) | ||
local balance = accounts:get(source, 'bank') | ||
local accounts = Ox.GetPlayer(source).getAccounts() | ||
local balance = accounts.get('bank') | ||
local amount = tonumber(data?.amount) | ||
|
||
if not amount or amount <= 0 or amount > balance then | ||
TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'error', | ||
description = 'Invalid amount' | ||
}) | ||
else | ||
accounts:remove(source, 'bank', amount) | ||
inventory:AddItem(source, 'money', amount) | ||
accounts.remove('bank', amount) | ||
ox_inventory:AddItem(source, 'money', amount) | ||
|
||
TriggerClientEvent('orp_banking:update', source, balance - amount) | ||
TriggerClientEvent('orp_banking:notify', source, 'You have successfully withdrawn $'.. amount, 'success') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'success', | ||
description = 'You have successfully withdrawn $'.. amount | ||
}) | ||
end | ||
end) | ||
|
||
RegisterNetEvent('orp_banking:transfer', function(data) | ||
local amount = tonumber(data?.amount) | ||
|
||
if type(data?.target) ~= 'number' then | ||
TriggerClientEvent('orp_banking:notify', source, 'Recipient not found', 'error') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'error', | ||
description = 'Recipient not found' | ||
}) | ||
elseif data?.target == source then | ||
TriggerClientEvent('orp_banking:notify', source, 'You cannot transfer money to yourself', 'error') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'error', | ||
description = 'You cannot transfer money to yourself' | ||
}) | ||
elseif not amount or amount <= 0 then | ||
TriggerClientEvent('orp_banking:notify', source, 'Invalid amount', 'error') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'error', | ||
description = 'Invalid amount' | ||
}) | ||
else | ||
local balance = accounts:get(source, 'bank') | ||
local accounts = Ox.GetPlayer(source).getAccounts() | ||
local balance = accounts.get('bank') | ||
|
||
if balance <= 0 or balance < amount or amount <= 0 then | ||
TriggerClientEvent('orp_banking:notify', source, 'You don\'t have enough money for this transfer', 'error') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'error', | ||
description = 'You don\'t have enough money for this transfer' | ||
}) | ||
else | ||
accounts:remove(source, 'bank', amount) | ||
accounts.remove('bank', amount) | ||
TriggerClientEvent('orp_banking:update', source, balance - amount) | ||
TriggerClientEvent('orp_banking:notify', source, 'You have successfully transferred $'.. amount, 'success') | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'success', | ||
description = 'You have successfully transferred $'.. amount | ||
}) | ||
|
||
accounts:add(data.target, 'bank', amount) | ||
TriggerClientEvent('orp_banking:update', source, accounts:get(data.target, 'bank')) | ||
TriggerClientEvent('orp_banking:notify', source, 'You just received $'.. amount ..' via bank transfer', 'success') | ||
local target = Ox.GetPlayer(data.target).getAccounts() | ||
target.add('bank', amount) | ||
TriggerClientEvent('orp_banking:update', source, target.get('bank')) | ||
TriggerClientEvent('ox_lib:notify', source, { | ||
type = 'success', | ||
description = 'You just received $'.. amount ..' via bank transfer' | ||
}) | ||
end | ||
end | ||
end) |