From e9885a22f2d8cd55bd213f77b5412955c22ab3d8 Mon Sep 17 00:00:00 2001 From: Linden Date: Sat, 26 Jun 2021 05:30:57 +1000 Subject: [PATCH] improvement(server): Changed method to retrieve ESX.Jobs; do not define grade if unemployed; use ESX import for server --- fxmanifest.lua | 5 +++-- server/functions.lua | 8 ++++++++ server/main.lua | 21 ++++++--------------- 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 server/functions.lua diff --git a/fxmanifest.lua b/fxmanifest.lua index 9baedcb6..2916b49e 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,7 +1,7 @@ fx_version 'adamant' game 'gta5' description 'https://github.com/thelindat/esx_multicharacter' -version '1.1.0' +version '1.1.1' dependencies { 'es_extended', @@ -13,8 +13,9 @@ dependencies { shared_script 'config.lua' server_scripts { + '@es_extended/imports.lua', '@mysql-async/lib/MySQL.lua', - 'server/main.lua', + 'server/*.lua', } client_scripts { diff --git a/server/functions.lua b/server/functions.lua new file mode 100644 index 00000000..a1312e0a --- /dev/null +++ b/server/functions.lua @@ -0,0 +1,8 @@ +GetJobs = function() + local jobs = {} + while next(jobs) == nil do + Citizen.Wait(250) + jobs = exports['es_extended']:getSharedObject().Jobs + end + return jobs +end \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 0bbcca8c..7ba0df86 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,5 +1,6 @@ -ESX = exports['es_extended']:getSharedObject() -if ESX.GetConfig().Multichar == true then +if not ESX then + SetTimeout(3000, print('[^3WARNING^7] Unable to start Multicharacter - your version of ESX is not compatible ')) +elseif ESX.GetConfig().Multichar == true then local fetchCharacters = -1 local IdentifierTables = {} @@ -27,12 +28,10 @@ if ESX.GetConfig().Multichar == true then }, function(result) local characters = {} for i=1, #result, 1 do - local job, grade = result[1].job, tostring(result[1].job_grade) + local job, grade = result[1].job or 'unemployed', tostring(result[1].job_grade) if ESX.Jobs[job] and ESX.Jobs[job].grades[grade] then - grade = ESX.Jobs[job].grades[grade].label + if job ~= 'unemployed' then grade = ESX.Jobs[job].grades[grade].label else grade = '' end job = ESX.Jobs[job].label - else - job, grade = 'Unemployed', '' end local accounts = json.decode(result[i].accounts) local id = tonumber(string.sub(result[i].identifier, #Config.Prefix+1, string.find(result[i].identifier, ':')-1)) @@ -81,11 +80,7 @@ if ESX.GetConfig().Multichar == true then end end) end) - - while next(ESX.Jobs) == nil do - Citizen.Wait(250) - ESX.Jobs = exports['es_extended']:getSharedObject().Jobs - end + if not next(ESX.Jobs) then ESX.Jobs = GetJobs() end end) RegisterServerEvent("esx_multicharacter:SetupCharacters") @@ -139,9 +134,5 @@ if ESX.GetConfig().Multichar == true then end, true) elseif ESX.GetConfig().Multichar == false then - SetTimeout(1000, print('[^3WARNING^7] Multicharacter is disabled - please check your ESX configuration')) SetTimeout(3000, print('[^3WARNING^7] Multicharacter is disabled - please check your ESX configuration')) -else - SetTimeout(1000, print('[^3WARNING^7] Unable to start Multicharacter - your version of ESX is not compatible ')) - SetTimeout(3000, print('[^3WARNING^7] Unable to start Multicharacter - your version of ESX is not compatible ')) end