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) status.remove(75)
end) end)
Citizen.CreateThread(function() end)
while true do
Citizen.Wait(1000)
local playerPed = PlayerPedId() AddEventHandler('esx_status:onTick', function(data)
local prevHealth = GetEntityHealth(playerPed) local playerPed = PlayerPedId()
local health = prevHealth local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth
TriggerEvent('esx_status:getStatus', 'hunger', function(status)
if status.val == 0 then for k, v in pairs(data) do
if prevHealth <= 150 then if v.name == 'hunger' and v.percent == 0 then
health = health - 5 if prevHealth <= 150 then
else health = health - 5
health = health - 1 else
end health = health - 1
end end
end) elseif v.name == 'thirst' and v.percent == 0 then
if prevHealth <= 150 then
TriggerEvent('esx_status:getStatus', 'thirst', function(status) health = health - 5
if status.val == 0 then else
if prevHealth <= 150 then health = health - 1
health = health - 5
else
health = health - 1
end
end
end)
if health ~= prevHealth then
SetEntityHealth(playerPed, health)
end end
end end
end) end
if health ~= prevHealth then SetEntityHealth(playerPed, health) end
end) end)
AddEventHandler('esx_basicneeds:isEating', function(cb) AddEventHandler('esx_basicneeds:isEating', function(cb)