Follow same format for societybank.lua

Hopefully becomes easier for devs to add their banking functions to this
This commit is contained in:
Jim Shield
2025-08-13 18:41:07 +01:00
parent 345a81aaf7
commit 3b959b8567

View File

@@ -11,20 +11,10 @@
• Tgiann-bank • Tgiann-bank
]] ]]
--- Retrieves the current balance of a society's bank account. local societyFunc = {
--- @param society string The identifier of the society. {
--- @return number number The current account balance. bankName = "qb-banking",
--- @usage getAccount = function(society)
--- ```lua
--- local balance = getSocietyAccount("police")
--- print("Police account balance: $"..balance)
--- ```
function getSocietyAccount(society)
local bankScript, amount = "", 0
if society == nil or society == "none" then return amount end
if isStarted("qb-banking") then
bankScript = "qb-banking"
if not exports["qb-banking"]:GetAccount(society) then if not exports["qb-banking"]:GetAccount(society) then
if Jobs[society] then if Jobs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'") print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
@@ -36,56 +26,9 @@ function getSocietyAccount(society)
Wait(150) Wait(150)
end end
end end
amount = exports["qb-banking"]:GetAccountBalance(society) return exports["qb-banking"]:GetAccountBalance(society)
end,
--elseif isStarted("esx_society") then chargeSociety = function(society, amount)
-- bankScript = "esx_society"
-- -- Since esx_society does not have a native client export for retrieving money,
-- -- we use a server callback to get the final amount.
-- amount = triggerCallback(getScript()..":getESXSocietyAccount", society) or 0
elseif isStarted("Renewed-Banking") then
bankScript = "Renewed-Banking"
amount = exports["Renewed-Banking"]:getAccountMoney(society)
elseif isStarted("fd_banking") then
bankScript = "fd_banking"
amount = exports["fd_banking"]:GetAccount(society)
elseif isStarted("okokBanking") then
bankScript = "okokBanking"
amount = exports['okokBanking']:GetAccount(society)
elseif isStarted("tgiann-bank") then
bankScript = "tgiann-bank"
if Jobs[society] then
amount = exports["tgiann-bank"]:GetJobAccountBalance(society)
else
amount = exports["tgiann-bank"]:GetGangAccountBalance(society)
end
end
if bankScript == "" then
print("^1Error^7: ^3GetSocietyAccount^7: ^2No supported banking script found")
else
debugPrint("^6Bridge^7: ^3"..bankScript.."^7: ^2Retrieved account ^7'^6"..society.."^7' ($"..amount..")")
end
return amount
end
--- Deducts funds from a society's bank account.
--- @param society string The identifier of the society.
--- @param amount number The amount of money to remove.
--- @usage
--- ```lua
--- chargeSociety("police", 1000)
--- ```
function chargeSociety(society, amount)
local bankScript, newAmount = "", 0
if isStarted("qb-banking") then
bankScript = "qb-banking"
if not exports["qb-banking"]:GetAccount(society) then if not exports["qb-banking"]:GetAccount(society) then
if Jobs[society] then if Jobs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'") print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
@@ -96,53 +39,8 @@ function chargeSociety(society, amount)
end end
end end
exports["qb-banking"]:RemoveMoney(society, amount) exports["qb-banking"]:RemoveMoney(society, amount)
--elseif isStarted("esx_society") then end,
-- bankScript = "esx_society" fundSociety = function(society, amount)
-- TriggerEvent("esx_society:withdrawMoney", society, amount)
elseif isStarted("Renewed-Banking") then
bankScript = "Renewed-Banking"
exports['Renewed-Banking']:removeAccountMoney(society, amount)
elseif isStarted("fd_banking") then
bankScript = "fd_banking"
exports["fd_banking"]:RemoveMoney(society, amount)
elseif isStarted("okokBanking") then
bankScript = "okokBanking"
exports['okokBanking']:RemoveMoney(society, amount)
elseif isStarted("tgiann-bank") then
bankScript = "tgiann-bank"
if Jobs[society] then
exports["tgiann-bank"]:RemoveJobMoney(society, amount)
else
exports["tgiann-bank"]:RemoveGangMoney(society, amount)
end
end
if bankScript == "" then
print("^1Error^7: ^3ChargeSociety^7: ^2No supported banking script found")
else
newAmount = getSocietyAccount(society)
debugPrint("^6Bridge^7: ^3"..bankScript.."^7: ^2Removing $"..amount.." from account '^6"..society.."^7' ($"..newAmount..")")
end
end
--- Adds funds to a society's bank account.
--- @param society string The identifier of the society.
--- @param amount number The amount of money to add.
--- @usage
--- ```lua
--- fundSociety("police", 500)
--- ```
function fundSociety(society, amount)
local bankScript, newAmount, success = "", 0, false
if isStarted("qb-banking") then
bankScript = "qb-banking"
if not exports["qb-banking"]:GetAccount(society) then if not exports["qb-banking"]:GetAccount(society) then
if Jobs[society] then if Jobs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'") print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
@@ -155,41 +53,140 @@ function fundSociety(society, amount)
end end
end end
exports["qb-banking"]:AddMoney(society, amount) exports["qb-banking"]:AddMoney(society, amount)
end,
},
--elseif isStarted("esx_society") then {
-- bankScript = "esx_society" bankName = "Renewed-Banking",
-- -- Use the esx_society event to deposit money. getAccount = function(society)
-- TriggerServerEvent('esx_society:depositMoney', society, amount) return exports["Renewed-Banking"]:getAccountMoney(society)
-- -- Use callback to return the updated balance. end,
-- newAmount = triggerCallback(getScript()..":getESXSocietyAccount", society) or 0 chargeSociety = function(society, amount)
exports['Renewed-Banking']:removeAccountMoney(society, amount)
elseif isStarted("Renewed-Banking") then end,
bankScript = "Renewed-Banking" fundSociety = function(society, amount)
exports['Renewed-Banking']:addAccountMoney(society, amount) exports['Renewed-Banking']:addAccountMoney(society, amount)
newAmount = exports["Renewed-Banking"]:getAccountMoney(society) end,
elseif isStarted("fd_banking") then },
bankScript = "fd_banking"
{
bankName = "fd_banking",
getAccount = function(society)
return exports["fd_banking"]:GetAccount(society)
end,
chargeSociety = function(society, amount)
exports["fd_banking"]:RemoveMoney(society, amount)
end,
fundSociety = function(society, amount)
exports["fd_banking"]:AddMoney(society, amount) exports["fd_banking"]:AddMoney(society, amount)
end,
},
elseif isStarted("okokBanking") then {
bankScript = "okokBanking" bankName = "okokBanking",
getAccount = function(society)
return exports['okokBanking']:GetAccount(society)
end,
chargeSociety = function(society, amount)
exports['okokBanking']:RemoveMoney(society, amount)
end,
fundSociety = function(society, amount)
exports['okokBanking']:AddMoney(society, amount) exports['okokBanking']:AddMoney(society, amount)
end,
},
elseif isStarted("tgiann-bank") then {
bankScript = "tgiann-bank" bankName = "tgiann-bank",
getAccount = function(society)
if Jobs[society] then
return exports["tgiann-bank"]:GetJobAccountBalance(society)
else
return exports["tgiann-bank"]:GetGangAccountBalance(society)
end
end,
chargeSociety = function(society, amount)
if Jobs[society] then
exports["tgiann-bank"]:RemoveJobMoney(society, amount)
else
exports["tgiann-bank"]:RemoveGangMoney(society, amount)
end
end,
fundSociety = function(society, amount)
if Jobs[society] then if Jobs[society] then
exports["tgiann-bank"]:AddJobMoney(society, amount) exports["tgiann-bank"]:AddJobMoney(society, amount)
else else
exports["tgiann-bank"]:AddGangMoney(society, amount) exports["tgiann-bank"]:AddGangMoney(society, amount)
end end
end,
},
}
--- Retrieves the current balance of a society's bank account.
--- @param society string The identifier of the society.
--- @return number number The current account balance.
--- @usage
--- ```lua
--- local balance = getSocietyAccount("police")
--- print("Police account balance: $"..balance)
--- ```
function getSocietyAccount(society)
local amount = 0
if society == nil or society == "none" then return amount end
for _, script in pairs(societyFunc) do
if isStarted(script.bankName) then
local amount = script.getAccount(society)
debugPrint("^6Bridge^7: ^3"..script.bankName.."^7: ^2Retrieved account ^7'^6"..society.."^7' ($"..tostring(amount)..")")
return amount
end
end end
if bankScript == "" then print("^1Error^7: ^3GetSocietyAccount^7: ^2No supported banking script found")
print("^1Error^7: ^3FundSociety^7: ^2No supported banking script found")
else return amount
newAmount = getSocietyAccount(society) end
debugPrint("^6Bridge^7: ^3"..bankScript.."^7: ^2Adding ^7$"..amount.." ^2to account ^7'^6"..society.."^7' ($"..newAmount..")")
--- Deducts funds from a society's bank account.
--- @param society string The identifier of the society.
--- @param amount number The amount of money to remove.
--- @usage
--- ```lua
--- chargeSociety("police", 1000)
--- ```
function chargeSociety(society, amount)
for _, script in pairs(societyFunc) do
if isStarted(script.bankName) then
script.chargeSociety(society, amount)
local newAmount = getSocietyAccount(society)
debugPrint("^6Bridge^7: ^3"..script.bankName.."^7: ^2Removing $"..amount.." from account '^6"..society.."^7' ($"..tostring(newAmount)..")")
return
end end
end
print("^1Error^7: ^3ChargeSociety^7: ^2No supported banking script found")
end
--- Adds funds to a society's bank account.
--- @param society string The identifier of the society.
--- @param amount number The amount of money to add.
--- @usage
--- ```lua
--- fundSociety("police", 500)
--- ```
function fundSociety(society, amount)
for _, script in pairs(societyFunc) do
if isStarted(script.bankName) then
script.fundSociety(society, amount)
local newAmount = getSocietyAccount(society)
debugPrint("^6Bridge^7: ^3"..script.bankName.."^7: ^2Adding ^7$"..amount.." ^2to account ^7'^6"..society.."^7' ($"..tostring(newAmount)..")")
return
end
end
print("^1Error^7: ^3FundSociety^7: ^2No supported banking script found")
end end