mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
improvements(boilerplate): Rename; add extra information and examples
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_size = 4
|
||||
indent_style = tab
|
||||
end_of_line = crlf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
@@ -1,16 +0,0 @@
|
||||
RegisterNetEvent('esx:playerLoaded')
|
||||
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew)
|
||||
ESX.PlayerData = xPlayer
|
||||
ESX.PlayerLoaded = true
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:playerLogout')
|
||||
AddEventHandler('esx:playerLogout', function(xPlayer, isNew)
|
||||
ESX.PlayerLoaded = false
|
||||
ESX.PlayerData = {}
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:setJob')
|
||||
AddEventHandler('esx:setJob', function(job)
|
||||
ESX.PlayerData.job = job
|
||||
end)
|
||||
@@ -0,0 +1,43 @@
|
||||
RegisterNetEvent('esx:playerLoaded') -- When a player loads their data, store their data
|
||||
AddEventHandler('esx:playerLoaded', function(xPlayer, 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)
|
||||
ESX.PlayerLoaded = false
|
||||
ESX.PlayerData = {}
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-- These two functions can perform the same task
|
||||
RegisterNetEvent('esx:setJob')
|
||||
AddEventHandler('esx:setJob', function(job)
|
||||
print('PlayerData.job was set to '..job)
|
||||
if ESX.PlayerData.job.name ~= job.name then
|
||||
print('You are now in a different job')
|
||||
end
|
||||
ESX.PlayerData.job = job
|
||||
end)
|
||||
|
||||
OnPlayerData = function(key, val, last)
|
||||
if type(val) == 'table' then val = json.encode(val) end
|
||||
print('PlayerData.'..key..' was set to '..val)
|
||||
if key == 'job' then
|
||||
if last.name ~= val.name then
|
||||
print('You are now in a different job')
|
||||
end
|
||||
elseif key == 'dead' then -- However, this function can be used for other PlayerData
|
||||
if val == true then
|
||||
print('You die too easily')
|
||||
SetTimeout(2000, function()
|
||||
if ESX.PlayerData.dead then
|
||||
print('Why are you still dead?')
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
-----------------------------------------------
|
||||
@@ -0,0 +1,16 @@
|
||||
RegisterNetEvent('esx:playerLoaded') -- When a player loads in, we can store some basic information about them locally
|
||||
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer, isNew)
|
||||
ESX.Players[playerId] = xPlayer.job.name
|
||||
end)
|
||||
|
||||
AddEventHandler('esx:playerDropped', function(playerId, reason) -- Remove the 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
|
||||
for playerId, xPlayer in pairs(ESX.Players) do
|
||||
print( ('%s %s is online with player id %s'):format(xPlayer.job.grade_label, xPlayer.name, playerId) )
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user