mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
chore(example): Provide more information
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
RegisterNetEvent('esx:playerLoaded') -- When a player loads their data, store their data
|
||||
RegisterNetEvent('esx:playerLoaded') -- Store the players data
|
||||
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew)
|
||||
ESX.PlayerData = xPlayer
|
||||
ESX.PlayerLoaded = true
|
||||
|
||||
@@ -3,20 +3,23 @@ AddEventHandler('esx:playerLoaded', function(playerId, xPlayer, isNew)
|
||||
ESX.Players[playerId] = xPlayer.job.name
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:setJob') -- When a player loads in, we can store some basic information about them locally
|
||||
RegisterNetEvent('esx:setJob') -- The stored data does not sync with the framework unless we tell it to
|
||||
AddEventHandler('esx:setJob', function(playerId, job, lastJob)
|
||||
ESX.Players[playerId] = job.name
|
||||
end)
|
||||
|
||||
AddEventHandler('esx:playerDropped', function(playerId, reason) -- Remove the data once the player no longer exists
|
||||
AddEventHandler('esx:playerDropped', function(playerId, reason) -- Remove any cached data once the player no longer exists
|
||||
ESX.Players[playerId] = nil
|
||||
end)
|
||||
|
||||
AddEventHandler('onResourceStart', function(resourceName) -- The resource just restarted so we actually have a fresh copy of ESX.Players from the framework
|
||||
if (GetCurrentResourceName() == resourceName) then -- Useful if we need to run functions or send events after a restart
|
||||
for playerId, xPlayer in pairs(ESX.Players) do
|
||||
local players = {}
|
||||
for _, xPlayer in pairs(ESX.Players) do
|
||||
players[playerId] = xPlayer.job.name
|
||||
print( ('%s %s is online with player id %s'):format(xPlayer.job.grade_label, xPlayer.name, playerId) )
|
||||
end
|
||||
ESX.Players = players -- Replace the data as it is a waste of memory
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user