Merge pull request #53 from thelindat/patch-1

improvement(client/main): Minor optimisation - use the esx_status:onTick event
This commit is contained in:
ESXCrackhead
2021-06-23 08:04:53 -05:00
committed by GitHub
+21 -30
View File
@@ -51,39 +51,30 @@ AddEventHandler('esx_status:loaded', function(status)
status.remove(75)
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
end)
local playerPed = PlayerPedId()
local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth
TriggerEvent('esx_status:getStatus', 'hunger', function(status)
if status.val == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
TriggerEvent('esx_status:getStatus', 'thirst', function(status)
if status.val == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
if health ~= prevHealth then
SetEntityHealth(playerPed, health)
AddEventHandler('esx_status:onTick', function(data)
local playerPed = PlayerPedId()
local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth
for k, v in pairs(data) do
if v.name == 'hunger' and v.percent == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
elseif v.name == 'thirst' and v.percent == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
end
if health ~= prevHealth then SetEntityHealth(playerPed, health) end
end)
AddEventHandler('esx_basicneeds:isEating', function(cb)