mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 09:18:53 +00:00
fix(society): Fix xPlayer loop and callbacks
This commit is contained in:
@@ -148,7 +148,7 @@ elseif not Config.UseDeferrals then
|
||||
end
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
if xPlayer then
|
||||
checkIdentity(xPlayer)
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ ESX.RegisterServerCallback('esx_bankerjob:getCustomers', function (source, cb)
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
local customers = {}
|
||||
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
|
||||
TriggerEvent('esx_addonaccount:getAccount', 'bank_savings', xPlayer.identifier, function(account)
|
||||
table.insert(customers, {
|
||||
|
||||
@@ -7,7 +7,7 @@ AddEventHandler('esx_holdup:tooFar', function(currentStore)
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
rob = false
|
||||
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
if xPlayer.job.name == 'police' then
|
||||
TriggerClientEvent('esx:showNotification', playerId, _U('robbery_cancelled_at', Stores[currentStore].nameOfStore))
|
||||
TriggerClientEvent('esx_holdup:killBlip', playerId)
|
||||
@@ -36,7 +36,7 @@ AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
||||
end
|
||||
|
||||
local cops = 0
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
if xPlayer.job.name == 'police' then
|
||||
cops = cops + 1
|
||||
end
|
||||
@@ -46,7 +46,7 @@ AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
||||
if cops >= Config.PoliceNumberRequired then
|
||||
rob = true
|
||||
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
if xPlayer.job.name == 'police' then
|
||||
TriggerClientEvent('esx:showNotification', playerId, _U('rob_in_prog', store.nameOfStore))
|
||||
TriggerClientEvent('esx_holdup:setBlip', playerId, Stores[currentStore].position)
|
||||
@@ -75,7 +75,7 @@ AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
||||
end
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
if xPlayer.job.name == 'police' then
|
||||
TriggerClientEvent('esx:showNotification', playerId, _U('robbery_complete_at', store.nameOfStore))
|
||||
TriggerClientEvent('esx_holdup:killBlip', playerId)
|
||||
|
||||
@@ -1500,7 +1500,6 @@ AddEventHandler('esx_policejob:updateBlip', function()
|
||||
-- Is the player a cop? In that case show all the blips for other cops
|
||||
if ESX.PlayerData.job and ESX.PlayerData.job.name == 'police' then
|
||||
ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
|
||||
print(ESX.DumpTable(players))
|
||||
for i=1, #players, 1 do
|
||||
if players[i].job.name == 'police' then
|
||||
local id = GetPlayerFromServerId(players[i].source)
|
||||
@@ -1514,7 +1513,7 @@ AddEventHandler('esx_policejob:updateBlip', function()
|
||||
|
||||
end)
|
||||
|
||||
AddEventHandler('playerSpawned', function(spawn)
|
||||
AddEventHandler('esx:onPlayerSpawn', function(spawn)
|
||||
isDead = false
|
||||
TriggerEvent('esx_policejob:unrestrain')
|
||||
|
||||
|
||||
@@ -168,8 +168,7 @@ ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, soci
|
||||
local employees = {}
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for i=1, #xPlayers do
|
||||
local xPlayer = xPlayers[i]
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
|
||||
local name = xPlayer.name
|
||||
if Config.EnableESXIdentity and name == GetPlayerName(xPlayer.source) then
|
||||
@@ -215,7 +214,7 @@ ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, soci
|
||||
|
||||
if Config.EnableESXIdentity then
|
||||
name = row.firstname .. ' ' .. row.lastname
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(employees, {
|
||||
name = name,
|
||||
@@ -300,8 +299,7 @@ ESX.RegisterServerCallback('esx_society:setJobSalary', function(source, cb, job,
|
||||
Jobs[job].grades[tostring(grade)].salary = salary
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for i=1, #xPlayers do
|
||||
local xTarget = xPlayers[i]
|
||||
for playerId, xTarget in pairs(xPlayers) do
|
||||
|
||||
if xTarget.job.name == job and xTarget.job.grade == grade then
|
||||
xTarget.setJob(job, grade)
|
||||
@@ -320,17 +318,13 @@ ESX.RegisterServerCallback('esx_society:setJobSalary', function(source, cb, job,
|
||||
end
|
||||
end)
|
||||
|
||||
local getOnlinePlayers = false
|
||||
local onlinePlayers = {}
|
||||
|
||||
local getOnlinePlayers, onlinePlayers = false, nil
|
||||
ESX.RegisterServerCallback('esx_society:getOnlinePlayers', function(source, cb)
|
||||
if getOnlinePlayers == false and next(onlinePlayers) == nil then -- Prevent multiple xPlayer loops from running in quick succession
|
||||
if getOnlinePlayers ~= true then -- Prevent multiple xPlayer loops from running in quick succession
|
||||
getOnlinePlayers, onlinePlayers = true, {}
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for i=1, #xPlayers do
|
||||
local xPlayer = xPlayers[i]
|
||||
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
table.insert(onlinePlayers, {
|
||||
source = xPlayer.source,
|
||||
identifier = xPlayer.identifier,
|
||||
@@ -340,7 +334,7 @@ ESX.RegisterServerCallback('esx_society:getOnlinePlayers', function(source, cb)
|
||||
end
|
||||
getOnlinePlayers = false
|
||||
end
|
||||
while getOnlinePlayers do Citizen.Wait(50) end -- Wait for the xPlayer loop to finish
|
||||
while getOnlinePlayers do Citizen.Wait(100) end -- Wait for the xPlayer loop to finish
|
||||
cb(onlinePlayers)
|
||||
end)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ AddEventHandler('onResourceStart', function(resourceName)
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}, function(result)
|
||||
@@ -98,7 +98,7 @@ function SaveData()
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
|
||||
for playerId, xPlayer in pairs(xPlayers)
|
||||
for playerId, xPlayer in pairs(xPlayers) do
|
||||
local status = Status[xPlayer.source]
|
||||
|
||||
whenList = whenList .. string.format('when identifier = \'%s\' then \'%s\' ', xPlayer.identifier, json.encode(status))
|
||||
|
||||
@@ -37,7 +37,7 @@ AddEventHandler('onClientMapStart', function()
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('playerSpawned', function()
|
||||
AddEventHandler('esx:onPlayerSpawn', function()
|
||||
NetworkSetTalkerProximity(voice.default)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user