Parent : [[INDEX-FIVEM-GAMEPLAY]]
FiveM - Status Tick & Damage : dégâts progressifs par statut faim/soif
Problème
Les besoins de base (faim, soif) doivent impacter la santé du joueur s'ils atteignent 0%, avec une difficulté progressive.
Solution
Tick client de statut avec dégâts progressifs basés sur le pourcentage de statut, intégration ESX status system, et seuil critique (santé ≤ 150 → dégâts x5).
AddEventHandler('esx_status:onTick', function(statuses)
local playerPed = PlayerPedId()
local prevHealth = GetEntityHealth(playerPed)
local newHealth = prevHealth
for _, status in pairs(statuses) do
if status.percent == 0 then
-- Dégâts progressifs : critique si santé faible
local damage = (prevHealth <= 150) and 5 or 1
if status.name == 'hunger' or status.name == 'thirst' then
newHealth = newHealth - damage
end
end
end
if newHealth ~= prevHealth then
SetEntityHealth(playerPed, newHealth)
end
end)
-- Registration des statuts au chargement
AddEventHandler('esx_status:loaded', function()
local function registerStatus(name, color, removalRate)
TriggerEvent('esx_status:registerStatus', name, 1000000, color,
function() return Config.Visible end,
function(status) status.remove(removalRate) end
)
end
registerStatus('hunger', '#CFAD0F', 100) -- 100 / 1000000 par tick
registerStatus('thirst', '#0C98F1', 75) -- 75 / 1000000 par tick
end)
Pourquoi
- Le tick est géré par
esx_status(pas de thread custom) - Dégâts x5 sous 150 HP créent une urgence réaliste
1000000est l'échelle interne ESX (0-100% mappé)
Quand l'utiliser
- Systèmes de survie (faim, soif, fatigue, température)
- Tout statut qui doit impacter la santé à terme
Quand NE PAS l'utiliser
- Si vous utilisez un système de statut alternatif (ox_status, QBCore)
Exemples
Correct
-- Multi-statuts avec effets différents
AddEventHandler('esx_status:onTick', function(statuses)
local ped = PlayerPedId()
local health = GetEntityHealth(ped)
for _, s in pairs(statuses) do
if s.percent == 0 then
if s.name == 'hunger' then
health = health - 1
elseif s.name == 'thirst' then
health = health - 2
elseif s.name == 'stress' then
SetPedMovementClipset(ped, 'move_m@drunk@slightlydrunk', true)
end
end
end
if health < GetEntityHealth(ped) then
SetEntityHealth(ped, math.max(health, 100))
end
end)
Incorrect
-- Thread custom séparé → conflit avec esx_status
CreateThread(function()
while true do
Wait(1000)
if hunger <= 0 then
local hp = GetEntityHealth(PlayerPedId())
SetEntityHealth(PlayerPedId(), hp - 1) -- Peut rentrer en conflit
end
end
end)
Références
- esx_basicneeds/client/main.lua L45-61
- esx_basicneeds/client/main.lua L33-43