2025-03-08 13:44:05 +00:00
|
|
|
--[[
|
|
|
|
|
Resource Initialization Module
|
|
|
|
|
--------------------------------
|
|
|
|
|
This module initializes and loads shared data (Items, Vehicles, Jobs, Gangs) from the
|
|
|
|
|
various frameworks/inventory systems (OX, QB, ESX, etc.). It also corrects export names,
|
|
|
|
|
caches framework exports into simple variables, and prints debug information if enabled.
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Global Variable Initialization
|
|
|
|
|
-------------------------------------------------------------
|
2025-05-07 23:01:29 +01:00
|
|
|
Items, Vehicles, Jobs, Gangs, Core = {}, nil, nil, nil, nil
|
2025-03-01 12:58:43 +00:00
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Correct QB Inventory Export
|
|
|
|
|
-------------------------------------------------------------
|
2025-05-07 13:32:54 +01:00
|
|
|
-- Correct ps-invetory to ls-inventory if somehow you still have that
|
|
|
|
|
Exports.PSInv = isStarted("lj-inventory") and "lj-inventory" or Exports.PSInv
|
2025-03-01 12:58:43 +00:00
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Framework Exports and Inventory Identifiers
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport =
|
|
|
|
|
Exports.OXLibExport or "",
|
|
|
|
|
Exports.QBXExport or "",
|
|
|
|
|
Exports.QBExport or "",
|
|
|
|
|
Exports.ESXExport or "",
|
|
|
|
|
Exports.OXCoreExport or ""
|
|
|
|
|
|
2025-04-30 17:53:26 +01:00
|
|
|
OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv =
|
2025-03-08 13:44:05 +00:00
|
|
|
Exports.OXInv or "",
|
|
|
|
|
Exports.QBInv or "",
|
|
|
|
|
Exports.PSInv or "",
|
|
|
|
|
Exports.QSInv or "",
|
|
|
|
|
Exports.CoreInv or "",
|
|
|
|
|
Exports.CodeMInv or "",
|
2025-04-30 17:53:26 +01:00
|
|
|
Exports.OrigenInv or "",
|
|
|
|
|
Exports.TgiannInv or ""
|
2025-03-01 12:58:43 +00:00
|
|
|
|
2025-04-07 20:52:59 +01:00
|
|
|
RSGExport, RSGInv =
|
|
|
|
|
Exports.RSGExport or "",
|
|
|
|
|
Exports.RSGInv or ""
|
|
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
QBMenuExport = Exports.QBMenuExport or ""
|
|
|
|
|
QBTargetExport, OXTargetExport = Exports.QBTargetExport or "", Exports.OXTargetExport or ""
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Debug: Print Found Exports
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Print a list of all exports that are currently started (if debugMode is enabled).
|
2025-03-01 12:58:43 +00:00
|
|
|
for _, v in pairs(Exports) do
|
2025-03-08 13:44:05 +00:00
|
|
|
if isStarted(v) then
|
|
|
|
|
debugPrint("^6Bridge^7: '^3"..v.."^7' export found")
|
|
|
|
|
end
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
|
2025-03-11 22:41:13 +00:00
|
|
|
OxPlayer = nil
|
|
|
|
|
if isStarted(OXCoreExport) then
|
|
|
|
|
if not isServer() then
|
|
|
|
|
OxPlayer = Ox.GetPlayer()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Resource Variables for Items, Jobs, and Vehicles
|
|
|
|
|
-------------------------------------------------------------
|
2025-03-01 12:58:43 +00:00
|
|
|
local itemResource, jobResource, vehResource = "", "", ""
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Loading Items
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Load and compile shared items from the detected inventory system.
|
2025-03-01 12:58:43 +00:00
|
|
|
if isStarted(OXInv) then
|
|
|
|
|
itemResource = OXInv
|
|
|
|
|
Items = exports[OXInv]:Items()
|
|
|
|
|
for k, v in pairs(Items) do
|
|
|
|
|
if v.client and v.client.image then
|
|
|
|
|
Items[k].image = (v.client.image):gsub("nui://"..OXInv.."/web/images/", "")
|
|
|
|
|
else
|
|
|
|
|
Items[k].image = k..".png"
|
|
|
|
|
end
|
|
|
|
|
Items[k].hunger = v.client and v.client.hunger or nil
|
|
|
|
|
Items[k].thirst = v.client and v.client.thirst or nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
elseif isStarted(QBExport) then
|
|
|
|
|
itemResource = QBExport
|
|
|
|
|
Core = Core or exports[QBExport]:GetCoreObject()
|
|
|
|
|
Items = Core and Core.Shared.Items or nil
|
2025-05-15 15:31:41 +01:00
|
|
|
CreateThread(function()
|
|
|
|
|
while not Items or not next(Items) do
|
|
|
|
|
Items = exports[QBExport]:GetCoreObject().Shared.Items
|
|
|
|
|
Wait(1000)
|
|
|
|
|
end
|
|
|
|
|
end)
|
2025-03-01 12:58:43 +00:00
|
|
|
if isStarted(QBExport) and not isStarted(QBXExport) then
|
|
|
|
|
RegisterNetEvent('QBCore:Client:UpdateObject', function()
|
|
|
|
|
Core = Core or exports[QBExport]:GetCoreObject()
|
|
|
|
|
Items = Core and Core.Shared.Items or nil
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
elseif isStarted(ESXExport) then
|
|
|
|
|
itemResource = ESXExport
|
|
|
|
|
CreateThread(function()
|
|
|
|
|
if isServer() then
|
2025-04-08 17:47:12 +01:00
|
|
|
Items = ESX.GetItems()
|
|
|
|
|
while not createCallback do Wait(100) end
|
2025-03-01 12:58:43 +00:00
|
|
|
createCallback(getScript()..":getItems", function(source)
|
|
|
|
|
return Items
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
if not isServer() then
|
|
|
|
|
Items = triggerCallback(getScript()..":getItems")
|
2025-03-08 13:44:05 +00:00
|
|
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7"..itemResource)
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
end)
|
2025-04-07 20:52:59 +01:00
|
|
|
|
|
|
|
|
elseif isStarted(RSGExport) then
|
|
|
|
|
itemResource = RSGExport
|
|
|
|
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
|
|
|
|
Items = Core and Core.Shared.Items or nil
|
2025-05-01 17:49:37 +01:00
|
|
|
RegisterNetEvent('RSGCore:Client:UpdateObject', function()
|
|
|
|
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
|
|
|
|
Items = Core and Core.Shared.Items or nil
|
|
|
|
|
end)
|
2025-04-07 20:52:59 +01:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
2025-04-08 17:47:12 +01:00
|
|
|
if itemResource == nil then
|
|
|
|
|
print("^4ERROR^7: ^2No Item info detected ^7- ^2Check ^3starter^1.^2lua^7")
|
|
|
|
|
else
|
|
|
|
|
while not Items do Wait(100) end
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7"..itemResource)
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
|
2025-04-08 17:47:12 +01:00
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Loading Vehicles
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Compile vehicles from the detected frameworks into a unified table.
|
2025-03-01 12:58:43 +00:00
|
|
|
if isStarted(QBXExport) or isStarted(QBExport) then
|
2025-05-07 23:01:29 +01:00
|
|
|
vehResource = QBExport
|
2025-03-01 12:58:43 +00:00
|
|
|
Core = Core or exports[QBExport]:GetCoreObject()
|
|
|
|
|
Vehicles = Core and Core.Shared.Vehicles
|
|
|
|
|
if isStarted(QBExport) and not isStarted(QBXExport) then
|
|
|
|
|
RegisterNetEvent('QBCore:Client:UpdateObject', function()
|
|
|
|
|
Core = Core or exports[QBExport]:GetCoreObject()
|
|
|
|
|
Vehicles = Core and Core.Shared.Vehicles
|
|
|
|
|
end)
|
|
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
elseif isStarted(OXCoreExport) then
|
2025-05-07 23:01:29 +01:00
|
|
|
vehResource = OXCoreExport
|
2025-03-01 12:58:43 +00:00
|
|
|
Vehicles = {}
|
|
|
|
|
for k, v in pairs(Ox.GetVehicleData()) do
|
2025-03-26 21:43:48 +00:00
|
|
|
Vehicles[k] = { model = k, hash = GetHashKey(k), price = v.price, name = v.name, brand = v.make }
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
elseif isStarted(ESXExport) then
|
2025-05-07 23:01:29 +01:00
|
|
|
vehResource = ESXExport
|
2025-03-01 12:58:43 +00:00
|
|
|
CreateThread(function()
|
|
|
|
|
if isServer() then
|
|
|
|
|
createCallback(getScript()..":getVehiclesPrices", function(source)
|
|
|
|
|
return Vehicles
|
|
|
|
|
end)
|
2025-04-18 16:14:42 +01:00
|
|
|
while not MySQL do Wait(2000) print("^1Waiting for MySQL to exist") end
|
2025-04-08 17:47:12 +01:00
|
|
|
Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles')
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
if not isServer() then
|
2025-04-08 17:47:12 +01:00
|
|
|
--while not triggerCallback do print("waiting") Wait(100) end
|
2025-03-01 12:58:43 +00:00
|
|
|
local TempVehicles = triggerCallback(getScript()..":getVehiclesPrices")
|
|
|
|
|
for _, v in pairs(TempVehicles) do
|
|
|
|
|
Vehicles = Vehicles or {}
|
2025-03-08 13:44:05 +00:00
|
|
|
Vehicles[v.model] = {
|
|
|
|
|
model = v.model,
|
2025-03-26 21:43:48 +00:00
|
|
|
hash = GetHashKey(v.model),
|
2025-03-08 13:44:05 +00:00
|
|
|
price = v.price,
|
|
|
|
|
name = v.name,
|
|
|
|
|
brand = GetMakeNameFromVehicleModel(v.model):lower():gsub("^%l", string.upper)
|
|
|
|
|
}
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
2025-04-07 20:52:59 +01:00
|
|
|
|
|
|
|
|
elseif isStarted(RSGExport) then
|
2025-05-07 23:01:29 +01:00
|
|
|
vehResource = RSGExport
|
2025-04-07 20:52:59 +01:00
|
|
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
|
|
|
|
Vehicles = Core and Core.Shared.Vehicles
|
2025-05-01 17:49:37 +01:00
|
|
|
RegisterNetEvent('RSGCore:Client:UpdateObject', function()
|
|
|
|
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
|
|
|
|
Vehicles = Core and Core.Shared.Vehicles
|
|
|
|
|
end)
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
if vehResource == nil then
|
2025-03-08 13:44:05 +00:00
|
|
|
print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7")
|
2025-03-01 12:58:43 +00:00
|
|
|
else
|
2025-04-18 19:45:56 +01:00
|
|
|
CreateThread(function()
|
2025-05-07 23:01:29 +01:00
|
|
|
while not Vehicles do Wait(1000) end
|
2025-04-18 19:45:56 +01:00
|
|
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource)
|
|
|
|
|
end)
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Loading Jobs and Gangs
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Compile jobs and gangs from the detected framework.
|
|
|
|
|
if isStarted(QBXExport) then
|
|
|
|
|
jobResource = QBXExport
|
2025-03-01 12:58:43 +00:00
|
|
|
Core = Core or exports[QBExport]:GetCoreObject()
|
|
|
|
|
Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs()
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
elseif isStarted(OXCoreExport) then
|
|
|
|
|
jobResource = OXExport
|
2025-03-01 12:58:43 +00:00
|
|
|
CreateThread(function()
|
|
|
|
|
if isServer() then
|
|
|
|
|
createCallback(getScript()..":getOxGroups", function(source)
|
2025-03-08 13:44:05 +00:00
|
|
|
Jobs = MySQL.query.await('SELECT * FROM `ox_groups`')
|
|
|
|
|
return Jobs
|
2025-03-01 12:58:43 +00:00
|
|
|
end)
|
|
|
|
|
else
|
|
|
|
|
local TempJobs = triggerCallback(getScript()..":getOxGroups")
|
2025-03-11 22:41:13 +00:00
|
|
|
Jobs = {}
|
2025-03-01 12:58:43 +00:00
|
|
|
for k, v in pairs(TempJobs) do
|
|
|
|
|
local grades = {}
|
2025-03-11 22:41:13 +00:00
|
|
|
--for i = 1, #v.grades do
|
|
|
|
|
-- grades[i] = { name = v.grades[i], isboss = (i == #v.grades) }
|
|
|
|
|
--end
|
2025-03-01 12:58:43 +00:00
|
|
|
Jobs[v.name] = { label = v.label, grades = grades }
|
|
|
|
|
end
|
|
|
|
|
Gangs = Jobs
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
elseif isStarted(QBExport) then
|
|
|
|
|
jobResource = QBExport
|
2025-03-01 12:58:43 +00:00
|
|
|
Core = Core or exports[QBExport]:GetCoreObject()
|
|
|
|
|
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
|
|
|
|
|
if isStarted(QBExport) and not isStarted(QBXExport) then
|
|
|
|
|
RegisterNetEvent('QBCore:Client:UpdateObject', function()
|
|
|
|
|
Core = exports[QBExport]:GetCoreObject()
|
|
|
|
|
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
elseif isStarted(ESXExport) then
|
2025-05-07 23:01:29 +01:00
|
|
|
jobResource = ESXExport
|
2025-03-01 12:58:43 +00:00
|
|
|
if isServer() then
|
2025-05-12 13:51:32 +01:00
|
|
|
-- If server, create callback to get jobs
|
|
|
|
|
createCallback(getScript()..":getESXJobs", function(source)
|
|
|
|
|
return Jobs
|
|
|
|
|
end)
|
|
|
|
|
-- Populate jobs table with ESX.GetJobs()
|
2025-03-01 12:58:43 +00:00
|
|
|
Jobs = ESX.GetJobs()
|
2025-05-12 13:51:32 +01:00
|
|
|
--If retreived jobs is empty, wait for ESX to load
|
|
|
|
|
while countTable(Jobs) == 0 do
|
|
|
|
|
Jobs = ESX.GetJobs()
|
|
|
|
|
Wait(100)
|
|
|
|
|
end
|
|
|
|
|
-- Organise into a table the script can use
|
2025-03-01 12:58:43 +00:00
|
|
|
for k, v in pairs(Jobs) do
|
2025-03-08 13:44:05 +00:00
|
|
|
local count = countTable(Jobs[k].grades) - 1
|
2025-03-01 12:58:43 +00:00
|
|
|
Jobs[k].grades[tostring(count)].isBoss = true
|
|
|
|
|
end
|
2025-05-12 13:51:32 +01:00
|
|
|
-- ESX Default doesn't have gangs, so copy jobs to gangs
|
|
|
|
|
Gangs = Jobs
|
|
|
|
|
end
|
|
|
|
|
-- If client side, trigger callback to get jobs
|
|
|
|
|
if not isServer() then
|
|
|
|
|
Jobs = triggerCallback(getScript()..":getESXJobs")
|
2025-03-01 12:58:43 +00:00
|
|
|
Gangs = Jobs
|
|
|
|
|
end
|
2025-04-07 20:52:59 +01:00
|
|
|
|
|
|
|
|
elseif isStarted(RSGExport) then
|
|
|
|
|
jobResource = RSGExport
|
|
|
|
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
|
|
|
|
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
|
2025-05-01 17:49:37 +01:00
|
|
|
RegisterNetEvent('RSGCore:Client:UpdateObject', function()
|
|
|
|
|
Core = exports[RSGExport]:GetCoreObject()
|
|
|
|
|
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
|
|
|
|
|
end)
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
2025-04-08 17:47:12 +01:00
|
|
|
if jobResource == nil then
|
|
|
|
|
print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7")
|
|
|
|
|
else
|
2025-05-12 13:51:32 +01:00
|
|
|
while not Jobs do Wait(1000) end
|
2025-03-08 13:44:05 +00:00
|
|
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource)
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource)
|
2025-04-08 17:47:12 +01:00
|
|
|
end
|