mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 09:48:52 +00:00
📦 save health and armour in the metadata, and load the metadata when the player joins
This commit is contained in:
@@ -59,6 +59,14 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
|
||||
end
|
||||
|
||||
local playerId = PlayerId()
|
||||
local metadata = ESX.PlayerData.metadata
|
||||
if metadata.health then
|
||||
SetEntityHealth(ESX.PlayerData.ped, metadata.health)
|
||||
end
|
||||
|
||||
if metadata.armor and metadata.armor > 0 then
|
||||
SetPedArmour(ESX.PlayerData.ped, metadata.armor)
|
||||
end
|
||||
|
||||
-- RemoveHudComponents
|
||||
for i = 1, #(Config.RemoveHudComponents) do
|
||||
|
||||
@@ -164,7 +164,14 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
||||
end
|
||||
end
|
||||
|
||||
local function updateHealthAndArmorInMetadata(xPlayer)
|
||||
local ped = GetPlayerPed(xPlayer.source)
|
||||
xPlayer.setMeta('health', GetEntityHealth(ped))
|
||||
xPlayer.setMeta('armor',GetPedArmour(ped))
|
||||
end
|
||||
|
||||
function Core.SavePlayer(xPlayer, cb)
|
||||
updateHealthAndArmorInMetadata(xPlayer)
|
||||
local parameters <const> = {
|
||||
json.encode(xPlayer.getAccounts(true)),
|
||||
xPlayer.job.name,
|
||||
@@ -202,6 +209,7 @@ function Core.SavePlayers(cb)
|
||||
local parameters = {}
|
||||
|
||||
for _, xPlayer in pairs(ESX.Players) do
|
||||
updateHealthAndArmorInMetadata(xPlayer)
|
||||
parameters[#parameters + 1] = {
|
||||
json.encode(xPlayer.getAccounts(true)),
|
||||
xPlayer.job.name,
|
||||
|
||||
@@ -81,7 +81,7 @@ function createESXPlayer(identifier, playerId, data)
|
||||
print(('[^2INFO^0] Player ^5%s^0 Has been granted admin permissions via ^5Ace Perms^7.'):format(playerId))
|
||||
defaultGroup = "admin"
|
||||
end
|
||||
|
||||
|
||||
local parameters = Config.Multichar and { json.encode(accounts), identifier, defaultGroup, data.firstname, data.lastname, data.dateofbirth, data.sex, data.height } or { json.encode(accounts), identifier, defaultGroup }
|
||||
|
||||
if Config.StartingInventoryItems then
|
||||
@@ -325,6 +325,12 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
xPlayer.set('height', userData.height)
|
||||
end
|
||||
end
|
||||
--saved player health and armor in metadata
|
||||
local ped = GetPlayerPed(xPlayer.source)
|
||||
if ped then
|
||||
xPlayer.setMeta('health', xPlayer.getMeta('health') or GetEntityHealth(ped))
|
||||
xPlayer.setMeta('armor', xPlayer.getMeta('armor') or GetPedArmour(ped))
|
||||
end
|
||||
|
||||
TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew)
|
||||
|
||||
@@ -713,7 +719,7 @@ local DoNotUse = {
|
||||
['default_spawnpoint'] = true,
|
||||
}
|
||||
|
||||
for key in pairs(DoNotUse) do
|
||||
for key in pairs(DoNotUse) do
|
||||
if GetResourceState(key) == 'started' or GetResourceState(key) == 'starting' then
|
||||
StopResource(key)
|
||||
print(("[^1ERROR^7] WE STOPPED A RESOURCE THAT WILL BREAK ^1ESX^7, PLEASE REMOVE ^5%s^7"):format(key))
|
||||
@@ -721,8 +727,8 @@ for key in pairs(DoNotUse) do
|
||||
end
|
||||
|
||||
AddEventHandler('onResourceStart', function(key)
|
||||
if DoNotUse[string.lower(key)] then
|
||||
if DoNotUse[string.lower(key)] then
|
||||
StopResource(key)
|
||||
print(("[^1ERROR^7] WE STOPPED A RESOURCE THAT WILL BREAK ^1ESX^7, PLEASE REMOVE ^5%s^7"):format(key))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user