playerStatus.lua
local hunger, thirst, stress = 0, 0, 0
function firstLoginUpdatePlayerStatus(PlayerData)
if config.tgiannServer then
hunger = PlayerData.metadata["hunger"] or 4230
thirst = PlayerData.metadata["thirst"] or 6500
stress = PlayerData.metadata["drunk"] or 0
elseif config.framework == "qb" then
hunger = PlayerData.metadata.hunger
if hunger > 100 then hunger = 100 end
thirst = PlayerData.metadata.thirst
if thirst > 100 then thirst = 100 end
stress = PlayerData.metadata.stress
if stress > 100 then stress = 100 end
end
end
function getPlayerStatus(playerPed, playerId)
local health = GetEntityHealth(playerPed) - 100
if health < 0 then health = 0 end
if config.tgiannServer then
hunger = exports["tgiann-hud"]:getStatusValue("hunger") / 100
thirst = exports["tgiann-hud"]:getStatusValue("water") / 100
end
return {
health = health,
armor = GetPedArmour(playerPed),
stamina = (100 - GetPlayerSprintStaminaRemaining(playerId)),
oxy = IsPedSwimmingUnderWater(playerPed) and GetPlayerUnderwaterTimeRemaining(playerId) or 100,
hunger = hunger,
thirst = thirst,
}
end
if config.framework == "esx" then
AddEventHandler('esx_status:onTick', function(data) -- Need Lastest version ESX STATUS - https://github.com/esx-framework/esx-legacy/tree/main/%5Besx_addons%5D/esx_status
for i = 1, #data do
if data[i].name == "hunger" then
hunger = data[i].percent
elseif data[i].name == "thirst" then
thirst = data[i].percent
end
end
end)
elseif config.framework == "qb" then
RegisterNetEvent('hud:client:UpdateNeeds')
AddEventHandler('hud:client:UpdateNeeds', function(newHunger, newThirst)
hunger = newHunger
if hunger > 100 then hunger = 100 end
thirst = newThirst
if thirst > 100 then thirst = 100 end
end)
RegisterNetEvent('hud:client:UpdateStress')
AddEventHandler('hud:client:UpdateStress', function(newStress)
stress = newStress
end)
end
Last updated