mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-18 22:36:04 +01:00
Refactor ESX Core loading
I realised I was loading ESX the stupidest way I think I was loading ESX object, then instantly clearing it and then used workarounds to try and reload it (thinking is hard ok) It should now load correctly and faster also I realised my custom `onPlayerLoaded()` function was loading too fast, so I've added a delay to it but removed the while loops for esx checks that could potentially break the script
This commit is contained in:
@@ -40,6 +40,7 @@ function onPlayerLoaded(func, onStart)
|
|||||||
|
|
||||||
if not loaded then
|
if not loaded then
|
||||||
local tempFunc = function()
|
local tempFunc = function()
|
||||||
|
Wait(2000)
|
||||||
debugPrint("^6Bridge^7: ^2Executing onPlayerLoaded")
|
debugPrint("^6Bridge^7: ^2Executing onPlayerLoaded")
|
||||||
func()
|
func()
|
||||||
end
|
end
|
||||||
@@ -138,9 +139,7 @@ function waitForLogin()
|
|||||||
local loggedIn = false
|
local loggedIn = false
|
||||||
|
|
||||||
if isStarted(ESXExport) then
|
if isStarted(ESXExport) then
|
||||||
debugPrint("^6Bridge^7: ^3ESX waitForLogin^7() ^2running^7")
|
|
||||||
while (GetGameTimer() - startTime) < timeout do
|
while (GetGameTimer() - startTime) < timeout do
|
||||||
while not ESX do Wait(100) end
|
|
||||||
local playerData = ESX.GetPlayerData()
|
local playerData = ESX.GetPlayerData()
|
||||||
if playerData and playerData.job then
|
if playerData and playerData.job then
|
||||||
loggedIn = true
|
loggedIn = true
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Global Variable Initialization
|
-- Global Variable Initialization
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil
|
Items, Vehicles, Jobs, Gangs, Core = {}, nil, nil, nil, nil
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Correct QB Inventory Export
|
-- Correct QB Inventory Export
|
||||||
@@ -96,13 +96,7 @@ elseif isStarted(QBExport) then
|
|||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
elseif isStarted(ESXExport) then
|
||||||
itemResource = ESXExport
|
itemResource = ESXExport
|
||||||
ESX = exports[ESXExport]:getSharedObject()
|
|
||||||
while ESX == nil do
|
|
||||||
print("Waiting for ESX")
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while not ESX do Wait(0) end
|
|
||||||
if isServer() then
|
if isServer() then
|
||||||
Items = ESX.GetItems()
|
Items = ESX.GetItems()
|
||||||
while not createCallback do Wait(100) end
|
while not createCallback do Wait(100) end
|
||||||
@@ -140,6 +134,7 @@ end
|
|||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Compile vehicles from the detected frameworks into a unified table.
|
-- Compile vehicles from the detected frameworks into a unified table.
|
||||||
if isStarted(QBXExport) or isStarted(QBExport) then
|
if isStarted(QBXExport) or isStarted(QBExport) then
|
||||||
|
vehResource = QBExport
|
||||||
Core = Core or exports[QBExport]:GetCoreObject()
|
Core = Core or exports[QBExport]:GetCoreObject()
|
||||||
Vehicles = Core and Core.Shared.Vehicles
|
Vehicles = Core and Core.Shared.Vehicles
|
||||||
if isStarted(QBExport) and not isStarted(QBXExport) then
|
if isStarted(QBExport) and not isStarted(QBXExport) then
|
||||||
@@ -148,26 +143,23 @@ if isStarted(QBXExport) or isStarted(QBExport) then
|
|||||||
Vehicles = Core and Core.Shared.Vehicles
|
Vehicles = Core and Core.Shared.Vehicles
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
vehResource = QBExport
|
|
||||||
|
|
||||||
elseif isStarted(OXCoreExport) then
|
elseif isStarted(OXCoreExport) then
|
||||||
|
vehResource = OXCoreExport
|
||||||
Vehicles = {}
|
Vehicles = {}
|
||||||
for k, v in pairs(Ox.GetVehicleData()) do
|
for k, v in pairs(Ox.GetVehicleData()) do
|
||||||
Vehicles[k] = { model = k, hash = GetHashKey(k), price = v.price, name = v.name, brand = v.make }
|
Vehicles[k] = { model = k, hash = GetHashKey(k), price = v.price, name = v.name, brand = v.make }
|
||||||
end
|
end
|
||||||
vehResource = OXCoreExport
|
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
elseif isStarted(ESXExport) then
|
||||||
|
vehResource = ESXExport
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
if isServer() then
|
if isServer() then
|
||||||
vehResource = ESXExport
|
|
||||||
createCallback(getScript()..":getVehiclesPrices", function(source)
|
createCallback(getScript()..":getVehiclesPrices", function(source)
|
||||||
return Vehicles
|
return Vehicles
|
||||||
end)
|
end)
|
||||||
while not MySQL do Wait(2000) print("^1Waiting for MySQL to exist") end
|
while not MySQL do Wait(2000) print("^1Waiting for MySQL to exist") end
|
||||||
Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles')
|
Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles')
|
||||||
--jsonPrint(Vehicles)
|
|
||||||
--while not createCallback do print("waiting") Wait(100) end
|
|
||||||
end
|
end
|
||||||
if not isServer() then
|
if not isServer() then
|
||||||
--while not triggerCallback do print("waiting") Wait(100) end
|
--while not triggerCallback do print("waiting") Wait(100) end
|
||||||
@@ -186,19 +178,19 @@ elseif isStarted(ESXExport) then
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
elseif isStarted(RSGExport) then
|
||||||
|
vehResource = RSGExport
|
||||||
Core = Core or exports[RSGExport]:GetCoreObject()
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
||||||
Vehicles = Core and Core.Shared.Vehicles
|
Vehicles = Core and Core.Shared.Vehicles
|
||||||
RegisterNetEvent('RSGCore:Client:UpdateObject', function()
|
RegisterNetEvent('RSGCore:Client:UpdateObject', function()
|
||||||
Core = Core or exports[RSGExport]:GetCoreObject()
|
Core = Core or exports[RSGExport]:GetCoreObject()
|
||||||
Vehicles = Core and Core.Shared.Vehicles
|
Vehicles = Core and Core.Shared.Vehicles
|
||||||
end)
|
end)
|
||||||
vehResource = RSGExport
|
|
||||||
end
|
end
|
||||||
if vehResource == nil then
|
if vehResource == nil then
|
||||||
print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7")
|
print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7")
|
||||||
else
|
else
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while not Vehicles do Wait(1000) print("Waiting") end
|
while not Vehicles do Wait(1000) end
|
||||||
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource)
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -246,7 +238,7 @@ elseif isStarted(QBExport) then
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
elseif isStarted(ESXExport) then
|
||||||
ESX = exports[ESXExport]:getSharedObject()
|
jobResource = ESXExport
|
||||||
if isServer() then
|
if isServer() then
|
||||||
Jobs = ESX.GetJobs()
|
Jobs = ESX.GetJobs()
|
||||||
for k, v in pairs(Jobs) do
|
for k, v in pairs(Jobs) do
|
||||||
@@ -256,7 +248,6 @@ elseif isStarted(ESXExport) then
|
|||||||
Gangs = Jobs
|
Gangs = Jobs
|
||||||
end
|
end
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while not ESX do Wait(0) end
|
|
||||||
if isServer() then
|
if isServer() then
|
||||||
createCallback(getScript()..":getJobs", function(source)
|
createCallback(getScript()..":getJobs", function(source)
|
||||||
return Jobs
|
return Jobs
|
||||||
|
|||||||
Reference in New Issue
Block a user