diff --git a/esx_example/client/main.lua b/esx_example/client/main.lua index 6a5da8b3..fe995759 100644 --- a/esx_example/client/main.lua +++ b/esx_example/client/main.lua @@ -1,11 +1,12 @@ RegisterNetEvent('esx:playerLoaded') -- Store the players data AddEventHandler('esx:playerLoaded', function(xPlayer, isNew) + print("Player Loaded. New | " .. isNew) ESX.PlayerData = xPlayer ESX.PlayerLoaded = true end) RegisterNetEvent('esx:playerLogout') -- When a player logs out (multicharacter), reset their data -AddEventHandler('esx:playerLogout', function(xPlayer, isNew) +AddEventHandler('esx:playerLogout', function() ESX.PlayerLoaded = false ESX.PlayerData = {} end) diff --git a/esx_example/server/main.lua b/esx_example/server/main.lua index 8f8b56e8..7507adbb 100644 --- a/esx_example/server/main.lua +++ b/esx_example/server/main.lua @@ -4,16 +4,19 @@ CreateThread(function() end) RegisterNetEvent('esx:playerLoaded') -- When a player loads in, we can store some basic information about them locally -AddEventHandler('esx:playerLoaded', function(playerId, xPlayer, isNew) +AddEventHandler('esx:playerLoaded', function(playerId, xPlayer) + print("Player | ".. playerId .. "spawned in") ESX.Players[playerId] = xPlayer.job.name end) RegisterNetEvent('esx:setJob') -- The stored data does not sync with the framework unless we tell it to -AddEventHandler('esx:setJob', function(playerId, job, lastJob) +AddEventHandler('esx:setJob', function(playerId, job) + print("Player | ".. playerId .. " | Changed Job. Job |".. job.label) ESX.Players[playerId] = job.name end) AddEventHandler('esx:playerDropped', function(playerId, reason) -- Remove any cached data once the player no longer exists + print("Player | ".. PlayerId .. "Dropped. Reason | ".. reason) ESX.Players[playerId] = nil end) @@ -28,10 +31,11 @@ AddEventHandler('onResourceStart', function(resourceName) -- The resource just r end end) -ESX.RegisterCommand('get', 'user', function(xPlayer, args, showError) +ESX.RegisterCommand('get', 'user', function(xPlayer, args) + print("Player |".. xPlayer.source.. "| Fetching all users.") local xPlayers = ESX.GetExtendedPlayers(args.key, args.val) -- New hitchless xPlayer loop, with the ability to only return players with specific data - for _, xPlayer in pairs(xPlayers) do -- Job and any non-table variable will work, ie. name, group, identifier, source - print(xPlayer.source, xPlayer.job.grade_label, xPlayer.name) + for _, xTarget in pairs(xPlayers) do -- Job and any non-table variable will work, ie. name, group, identifier, source + print("^1[ ^2ID : ^5".. xTarget.source.." ^0| ^2Name : ^5"..xTarget.getName().." ^0 | ^Job : ^5".. xTarget.job.label .." ^0 | ^2Identifier : ^5".. xTarget.identifier .."^1]^0\n") end end, true, {help = 'Display all online players with specific player data', validate = false, arguments = { {name = 'key', help = 'Variable to check (ie. job)', type = 'string'},