From e286bc86028222c19947a56c2202374db615b2f6 Mon Sep 17 00:00:00 2001 From: Linden Date: Mon, 5 Jul 2021 18:02:45 +1000 Subject: [PATCH] fix(society): Correct getOnlinePlayers behaviour Actually prevent multiple loops from running at once --- [esx_addons]/esx_society/server/main.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/[esx_addons]/esx_society/server/main.lua b/[esx_addons]/esx_society/server/main.lua index 08e0dc0e..0cab1a49 100644 --- a/[esx_addons]/esx_society/server/main.lua +++ b/[esx_addons]/esx_society/server/main.lua @@ -316,9 +316,9 @@ ESX.RegisterServerCallback('esx_society:setJobSalary', function(source, cb, job, end end) -local getOnlinePlayers, onlinePlayers = false, nil +local getOnlinePlayers, onlinePlayers = false, {} ESX.RegisterServerCallback('esx_society:getOnlinePlayers', function(source, cb) - if getOnlinePlayers ~= true then -- Prevent multiple xPlayer loops from running in quick succession + if getOnlinePlayers == false and next(onlinePlayers) == nil then -- Prevent multiple xPlayer loops from running in quick succession getOnlinePlayers, onlinePlayers = true, {} local xPlayers = ESX.GetExtendedPlayers() @@ -330,9 +330,13 @@ ESX.RegisterServerCallback('esx_society:getOnlinePlayers', function(source, cb) job = xPlayer.job }) end + cb(onlinePlayers) getOnlinePlayers = false + Citizen.Wait(1000) -- For the next second any extra requests will receive the cached list + onlinePlayers = {} + return end - while getOnlinePlayers do Citizen.Wait(100) end -- Wait for the xPlayer loop to finish + while getOnlinePlayers do Citizen.Wait(10) end -- Wait for the xPlayer loop to finish cb(onlinePlayers) end)