mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 01:38:52 +00:00
Refactor (esx_example (client &server )): Fix Formatting and add useful prints
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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'},
|
||||
|
||||
Reference in New Issue
Block a user