Changed to promise and deleted ESX.JobsLoaded

This commit is contained in:
Kr3mu
2025-07-29 15:34:09 +02:00
parent ef74169620
commit 19e697b211
3 changed files with 16 additions and 6 deletions
-5
View File
@@ -87,11 +87,6 @@ else
})
end
})
AddEventHandler("esx:jobsLoaded", function()
ESX.JobsLoaded = true
end)
end
if GetResourceState("ox_lib") == "missing" then
+1 -1
View File
@@ -1,7 +1,6 @@
ESX.Players = {}
ESX.Jobs = {}
ESX.Items = {}
ESX.JobsLoaded = false
Core = {}
Core.JobsPlayerCount = {}
Core.UsableItemsCallbacks = {}
@@ -11,6 +10,7 @@ Core.PickupId = 0
Core.PlayerFunctionOverrides = {}
Core.DatabaseConnected = false
Core.playersByIdentifier = {}
Core.JobsLoaded = promise:new()
---@type table<string, CVehicleData>
Core.vehicles = {}
+15
View File
@@ -505,6 +505,10 @@ end
---@return nil
function ESX.RefreshJobs()
if Core.JobsLoaded.value then
Core.JobsLoaded = promise:new()
end
local Jobs = {}
local jobs = MySQL.query.await("SELECT * FROM jobs")
@@ -538,6 +542,7 @@ function ESX.RefreshJobs()
end
TriggerEvent("esx:jobsLoaded")
Core.JobsLoaded:resolve(true)
end
---@param item string
@@ -597,6 +602,11 @@ end
---@return table
function ESX.GetJobs()
while not Core.JobsLoaded.value do
print("Waiting for ESX Jobs to Load")
Citizen.Wait(200)
end
return ESX.Jobs
end
@@ -763,6 +773,11 @@ end
---@param grade string
---@return boolean
function ESX.DoesJobExist(job, grade)
while not Core.JobsLoaded.value do
print("Waiting for ESX Jobs to Load")
Citizen.Wait(200)
end
return (ESX.Jobs[job] and ESX.Jobs[job].grades[tostring(grade)] ~= nil) or false
end