Refactor (esx_example (client &server )): Fix Formatting and add useful prints

This commit is contained in:
Mycroft
2022-04-06 19:41:19 +01:00
parent 9acf0b29d6
commit ba09b5fc4a
2 changed files with 11 additions and 6 deletions
+2 -1
View File
@@ -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)
+9 -5
View File
@@ -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'},