mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
improvement: Update xPlayer loops to use new function
This commit is contained in:
@@ -160,10 +160,10 @@ elseif not Config.UseDeferrals then
|
|||||||
Citizen.Wait(10)
|
Citizen.Wait(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
|
|
||||||
for i=1, #xPlayers, 1 do
|
for i=1, #xPlayers, 1 do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
local xPlayer = xPlayers[i]
|
||||||
|
|
||||||
if xPlayer then
|
if xPlayer then
|
||||||
checkIdentity(xPlayer)
|
checkIdentity(xPlayer)
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ AddEventHandler('esx_bankerjob:customerWithdraw', function (target, amount)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
ESX.RegisterServerCallback('esx_bankerjob:getCustomers', function (source, cb)
|
ESX.RegisterServerCallback('esx_bankerjob:getCustomers', function (source, cb)
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
local customers = {}
|
local customers = {}
|
||||||
|
|
||||||
for i=1, #xPlayers do
|
for i=1, #xPlayers do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
local xPlayer = xPlayers[i]
|
||||||
|
|
||||||
TriggerEvent('esx_addonaccount:getAccount', 'bank_savings', xPlayer.identifier, function(account)
|
TriggerEvent('esx_addonaccount:getAccount', 'bank_savings', xPlayer.identifier, function(account)
|
||||||
table.insert(customers, {
|
table.insert(customers, {
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
|||||||
RegisterServerEvent('esx_holdup:tooFar')
|
RegisterServerEvent('esx_holdup:tooFar')
|
||||||
AddEventHandler('esx_holdup:tooFar', function(currentStore)
|
AddEventHandler('esx_holdup:tooFar', function(currentStore)
|
||||||
local _source = source
|
local _source = source
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
rob = false
|
rob = false
|
||||||
|
|
||||||
for i=1, #xPlayers, 1 do
|
for i=1, #xPlayers, 1 do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
local xPlayer = xPlayers[i]
|
||||||
|
|
||||||
if xPlayer.job.name == 'police' then
|
if xPlayer.job.name == 'police' then
|
||||||
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('robbery_cancelled_at', Stores[currentStore].nameOfStore))
|
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('robbery_cancelled_at', Stores[currentStore].nameOfStore))
|
||||||
@@ -30,7 +30,7 @@ RegisterServerEvent('esx_holdup:robberyStarted')
|
|||||||
AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
||||||
local _source = source
|
local _source = source
|
||||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
|
|
||||||
if Stores[currentStore] then
|
if Stores[currentStore] then
|
||||||
local store = Stores[currentStore]
|
local store = Stores[currentStore]
|
||||||
@@ -42,7 +42,7 @@ AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
|||||||
|
|
||||||
local cops = 0
|
local cops = 0
|
||||||
for i=1, #xPlayers, 1 do
|
for i=1, #xPlayers, 1 do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
local xPlayer = xPlayers[i]
|
||||||
if xPlayer.job.name == 'police' then
|
if xPlayer.job.name == 'police' then
|
||||||
cops = cops + 1
|
cops = cops + 1
|
||||||
end
|
end
|
||||||
@@ -53,7 +53,7 @@ AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
|||||||
rob = true
|
rob = true
|
||||||
|
|
||||||
for i=1, #xPlayers, 1 do
|
for i=1, #xPlayers, 1 do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
local xPlayer = xPlayers[i]
|
||||||
if xPlayer.job.name == 'police' then
|
if xPlayer.job.name == 'police' then
|
||||||
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('rob_in_prog', store.nameOfStore))
|
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('rob_in_prog', store.nameOfStore))
|
||||||
TriggerClientEvent('esx_holdup:setBlip', xPlayers[i], Stores[currentStore].position)
|
TriggerClientEvent('esx_holdup:setBlip', xPlayers[i], Stores[currentStore].position)
|
||||||
@@ -81,9 +81,9 @@ AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
|
|||||||
xPlayer.addMoney(store.reward)
|
xPlayer.addMoney(store.reward)
|
||||||
end
|
end
|
||||||
|
|
||||||
local xPlayers, xPlayer = ESX.GetPlayers(), nil
|
local xPlayers, xPlayer = ESX.GetExtendedPlayers(), nil
|
||||||
for i=1, #xPlayers, 1 do
|
for i=1, #xPlayers, 1 do
|
||||||
xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
xPlayer = xPlayers[i]
|
||||||
|
|
||||||
if xPlayer.job.name == 'police' then
|
if xPlayer.job.name == 'police' then
|
||||||
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('robbery_complete_at', store.nameOfStore))
|
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('robbery_complete_at', store.nameOfStore))
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ local DisptachRequestId, PhoneNumbers = 0, {}
|
|||||||
TriggerEvent('esx:getSharedObject', function(obj)
|
TriggerEvent('esx:getSharedObject', function(obj)
|
||||||
ESX = obj
|
ESX = obj
|
||||||
|
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
|
|
||||||
for i=1, #xPlayers, 1 do
|
for i=1, #xPlayers, 1 do
|
||||||
LoadPlayer(xPlayers[i])
|
LoadPlayer(xPlayers[i])
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function LoadPlayer(source)
|
function LoadPlayer(player)
|
||||||
local xPlayer = ESX.GetPlayerFromId(source)
|
local xPlayer = player
|
||||||
|
|
||||||
for num,v in pairs(PhoneNumbers) do
|
for num,v in pairs(PhoneNumbers) do
|
||||||
if tonumber(num) == num then -- if phonenumber is a player phone number
|
if tonumber(num) == num then -- if phonenumber is a player phone number
|
||||||
@@ -107,8 +107,8 @@ AddEventHandler('esx_phone:getDistpatchRequestId', function(cb)
|
|||||||
cb(GetDistpatchRequestId())
|
cb(GetDistpatchRequestId())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
AddEventHandler('esx:playerLoaded', function(playerId)
|
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
|
||||||
LoadPlayer(playerId)
|
LoadPlayer(xPlayer)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
AddEventHandler('esx:playerDropped', function(source)
|
AddEventHandler('esx:playerDropped', function(source)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Config.MarkerColor = {r = 50, g = 50, b = 204}
|
|||||||
|
|
||||||
Config.EnablePlayerManagement = false -- Enable if you want society managing.
|
Config.EnablePlayerManagement = false -- Enable if you want society managing.
|
||||||
Config.EnableArmoryManagement = false
|
Config.EnableArmoryManagement = false
|
||||||
Config.EnableESXIdentity = false -- Enable if you're using esx_identity.
|
Config.EnableESXIdentity = true -- Enable if you're using esx_identity.
|
||||||
Config.EnableLicenses = false -- Enable if you're using esx_license.
|
Config.EnableLicenses = false -- Enable if you're using esx_license.
|
||||||
|
|
||||||
Config.EnableHandcuffTimer = true -- Enable handcuff timer? will unrestrain player after the time ends.
|
Config.EnableHandcuffTimer = true -- Enable handcuff timer? will unrestrain player after the time ends.
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ end)
|
|||||||
|
|
||||||
ESX.RegisterServerCallback('esx_realestateagentjob:getCustomers', function(source, cb)
|
ESX.RegisterServerCallback('esx_realestateagentjob:getCustomers', function(source, cb)
|
||||||
TriggerEvent('esx_ownedproperty:getOwnedProperties', function(properties)
|
TriggerEvent('esx_ownedproperty:getOwnedProperties', function(properties)
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
local customers = {}
|
local customers = {}
|
||||||
|
|
||||||
for i=1, #properties, 1 do
|
for i=1, #properties, 1 do
|
||||||
for j=1, #xPlayers, 1 do
|
for j=1, #xPlayers, 1 do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[j])
|
local xPlayer = xPlayers[j]
|
||||||
|
|
||||||
if xPlayer.identifier == properties[i].owner then
|
if xPlayer.identifier == properties[i].owner then
|
||||||
table.insert(customers, {
|
table.insert(customers, {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Config = {}
|
Config = {}
|
||||||
|
|
||||||
Config.Locale = 'en'
|
Config.Locale = 'en'
|
||||||
Config.EnableESXIdentity = false
|
Config.EnableESXIdentity = true
|
||||||
Config.MaxSalary = 3500
|
Config.MaxSalary = 3500
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ local Jobs = {}
|
|||||||
local RegisteredSocieties = {}
|
local RegisteredSocieties = {}
|
||||||
|
|
||||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||||
local isLegacy = not not ESX.GetExtendedPlayers
|
|
||||||
|
|
||||||
function GetSociety(name)
|
function GetSociety(name)
|
||||||
for i=1, #RegisteredSocieties, 1 do
|
for i=1, #RegisteredSocieties, 1 do
|
||||||
@@ -171,25 +170,25 @@ end)
|
|||||||
ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, society)
|
ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, society)
|
||||||
local employees = {}
|
local employees = {}
|
||||||
|
|
||||||
local xPlayers = isLegacy and ESX.GetExtendedPlayers() or ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
for k,v in pairs(xPlayers) do
|
for i=1, #xPlayers do
|
||||||
local xPlayer = type(v) == 'table' and v or ESX.GetPlayerFromId(v)
|
local xPlayer = xPlayers[i]
|
||||||
|
|
||||||
local name = GetPlayerName(xPlayer.source)
|
local name = xPlayer.name
|
||||||
if Config.EnableESXIdentity then
|
if Config.EnableESXIdentity and name == GetPlayerName(xPlayer.source) then
|
||||||
name = xPlayer.get('firstName') .. ' ' .. xPlayer.get('lastName')
|
name = xPlayer.get('firstName') .. ' ' .. xPlayer.get('lastName')
|
||||||
end
|
end
|
||||||
|
|
||||||
if xPlayer.getJob().name == society then
|
if xPlayer.job.name == society then
|
||||||
table.insert(employees, {
|
table.insert(employees, {
|
||||||
name = name,
|
name = name,
|
||||||
identifier = xPlayer.identifier,
|
identifier = xPlayer.identifier,
|
||||||
job = {
|
job = {
|
||||||
name = society,
|
name = society,
|
||||||
label = xPlayer.getJob().label,
|
label = xPlayer.job.label,
|
||||||
grade = xPlayer.getJob().grade,
|
grade = xPlayer.job.grade,
|
||||||
grade_name = xPlayer.getJob().grade_name,
|
grade_name = xPlayer.job.grade_name,
|
||||||
grade_label = xPlayer.getJob().grade_label
|
grade_label = xPlayer.job.grade_label
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -303,9 +302,9 @@ ESX.RegisterServerCallback('esx_society:setJobSalary', function(source, cb, job,
|
|||||||
}, function(rowsChanged)
|
}, function(rowsChanged)
|
||||||
Jobs[job].grades[tostring(grade)].salary = salary
|
Jobs[job].grades[tostring(grade)].salary = salary
|
||||||
|
|
||||||
local xPlayers = isLegacy and ESX.GetExtendedPlayers() or ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
for k,v in pairs(xPlayers) do
|
for i=1, #xPlayers do
|
||||||
local xTarget = type(v) == 'table' and v or ESX.GetPlayerFromId(v)
|
local xTarget = xPlayers[i]
|
||||||
|
|
||||||
if xTarget.job.name == job and xTarget.job.grade == grade then
|
if xTarget.job.name == job and xTarget.job.grade == grade then
|
||||||
xTarget.setJob(job, grade)
|
xTarget.setJob(job, grade)
|
||||||
@@ -331,9 +330,9 @@ 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 == false and next(onlinePlayers) == nil then -- Prevent multiple xPlayer loops from running in quick succession
|
||||||
getOnlinePlayers, onlinePlayers = true, {}
|
getOnlinePlayers, onlinePlayers = true, {}
|
||||||
|
|
||||||
local xPlayers = isLegacy and ESX.GetExtendedPlayers() or ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
for k,v in pairs(xPlayers) do
|
for i=1, #xPlayers do
|
||||||
local xPlayer = type(v) == 'table' and v or ESX.GetPlayerFromId(v)
|
local xPlayer = xPlayers[i]
|
||||||
|
|
||||||
table.insert(onlinePlayers, {
|
table.insert(onlinePlayers, {
|
||||||
source = xPlayer.source,
|
source = xPlayer.source,
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
ESX = nil
|
ESX = nil
|
||||||
|
|
||||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||||
local isLegacy = not not ESX.GetExtendedPlayers
|
|
||||||
|
|
||||||
AddEventHandler('onResourceStart', function(resourceName)
|
AddEventHandler('onResourceStart', function(resourceName)
|
||||||
if (GetCurrentResourceName() ~= resourceName) then
|
if (GetCurrentResourceName() ~= resourceName) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local xPlayers = isLegacy and ESX.GetExtendedPlayers() or ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
|
|
||||||
for k,v in pairs(xPlayers) do
|
for i=1, #xPlayers do
|
||||||
local xPlayer = type(v) == 'table' and v or ESX.GetPlayerFromId(v)
|
local xPlayer = xPlayers[i]
|
||||||
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
|
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
|
||||||
['@identifier'] = xPlayer.identifier
|
['@identifier'] = xPlayer.identifier
|
||||||
}, function(result)
|
}, function(result)
|
||||||
@@ -22,7 +21,7 @@ AddEventHandler('onResourceStart', function(resourceName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
xPlayer.set('status', data)
|
xPlayer.set('status', data)
|
||||||
TriggerClientEvent('esx_status:load', k, data)
|
TriggerClientEvent('esx_status:load', xPlayer.source, data)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -100,10 +99,10 @@ function SaveData()
|
|||||||
local firstItem = true
|
local firstItem = true
|
||||||
local playerCount = 0
|
local playerCount = 0
|
||||||
|
|
||||||
local xPlayers = isLegacy and ESX.GetExtendedPlayers() or ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
|
|
||||||
for k,v in pairs(xPlayers) do
|
for i=1, #xPlayers do
|
||||||
local xPlayer = type(v) == 'table' and v or ESX.GetPlayerFromId(v)
|
local xPlayer = xPlayers[i]
|
||||||
local status = xPlayer.get('status')
|
local status = xPlayer.get('status')
|
||||||
|
|
||||||
whenList = whenList .. string.format('when identifier = \'%s\' then \'%s\' ', xPlayer.identifier, json.encode(status))
|
whenList = whenList .. string.format('when identifier = \'%s\' then \'%s\' ', xPlayer.identifier, json.encode(status))
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ MySQL.ready(function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
|
AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
|
||||||
local xPlayers = ESX.GetPlayers()
|
local xPlayers = ESX.GetExtendedPlayers()
|
||||||
|
|
||||||
-- Mark this connection as deferred, this is to prevent problems while checking player identifiers.
|
-- Mark this connection as deferred, this is to prevent problems while checking player identifiers.
|
||||||
deferrals.defer()
|
deferrals.defer()
|
||||||
|
|
||||||
local playerId, kickReason, identifier = source
|
local playerId, kickReason = source
|
||||||
|
|
||||||
-- Letting the user know what's going on.
|
-- Letting the user know what's going on.
|
||||||
deferrals.update(_U('whitelist_check'))
|
deferrals.update(_U('whitelist_check'))
|
||||||
@@ -35,12 +35,7 @@ AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
|
|||||||
-- Needed, not sure why.
|
-- Needed, not sure why.
|
||||||
Citizen.Wait(100)
|
Citizen.Wait(100)
|
||||||
|
|
||||||
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
|
local identifier = ESX.GetIdentifier(playerId)
|
||||||
if string.match(v, 'license:') then
|
|
||||||
identifier = string.sub(v, 9)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ESX.Table.SizeOf(WhiteList) == 0 then
|
if ESX.Table.SizeOf(WhiteList) == 0 then
|
||||||
kickReason = _U('whitelist_empty')
|
kickReason = _U('whitelist_empty')
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ add_ace resource.es_extended command.stop allow
|
|||||||
## ESX Legacy
|
## ESX Legacy
|
||||||
ensure mysql-async
|
ensure mysql-async
|
||||||
ensure cron
|
ensure cron
|
||||||
ensure instance
|
|
||||||
ensure skinchanger
|
ensure skinchanger
|
||||||
ensure es_extended
|
ensure es_extended
|
||||||
ensure esx_menu_default
|
ensure esx_menu_default
|
||||||
|
|||||||
Reference in New Issue
Block a user