From 7aa9d90d0d059bdc0946e96d1686a777397e1caa Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 17 May 2025 16:48:23 +0100 Subject: [PATCH] Improve ESX Job cache builder When collecting Jobs from the server it tries it's best to determine which role is the "Boss" It checks first of the Job Grade label containing the word "Boss" If it can't find it, it then uses the highest number grade and adds `.isBoss = true` to it --- shared/coreloader.lua | 34 +++++++++++++++++++++++++++------- shared/jobfunctions.lua | 2 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/shared/coreloader.lua b/shared/coreloader.lua index 56d625b..81ce7bc 100644 --- a/shared/coreloader.lua +++ b/shared/coreloader.lua @@ -195,10 +195,8 @@ end if vehResource == nil then print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7") else - CreateThread(function() - while not Vehicles do Wait(1000) end - debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource) - end) + while not Vehicles do Wait(1000) end + debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource) end ------------------------------------------------------------- @@ -252,15 +250,37 @@ elseif isStarted(ESXExport) then end) -- Populate jobs table with ESX.GetJobs() Jobs = ESX.GetJobs() + --jsonPrint(Jobs) --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 - for k, v in pairs(Jobs) do - local count = countTable(Jobs[k].grades) - 1 - Jobs[k].grades[tostring(count)].isBoss = true + for Role, Grades in pairs(Jobs) do + + -- Check for "Boss" in name of grades + for grade, info in pairs(Grades.grades) do + --print(grade) + --jsonPrint(info) + + if info.label then + --print(info) + if info.label:find("boss") or info.label:find("Boss") then + --print("Found Boss label for:", Grades.label) + Jobs[Role].grades[grade].isBoss = true + goto continue + end + end + end + + -- If no roles with "boss" in the name, revert to max grade + + -- Count grades + local count = countTable(Grades.grades) + Jobs[Role].grades[tostring(count-1)].isBoss = true + --print(Grades.label.." Grade: "..count.." is Boss") + ::continue:: end -- ESX Default doesn't have gangs, so copy jobs to gangs Gangs = Jobs diff --git a/shared/jobfunctions.lua b/shared/jobfunctions.lua index 910b74c..8b6a0c6 100644 --- a/shared/jobfunctions.lua +++ b/shared/jobfunctions.lua @@ -46,7 +46,7 @@ function makeBossRoles(role) local data = (Jobs and Jobs[role]) or (Gangs and Gangs[role]) if data then for grade, info in pairs(data.grades) do - if info.isboss or info.bankAuth then + if info.isboss or info.bankAuth or info.isBoss then boss[role] = boss[role] and math.min(boss[role], tonumber(grade)) or tonumber(grade) end end