mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 23:01:30 +00:00
Merge pull request #53 from thelindat/patch-1
improvement(client/main): Minor optimisation - use the esx_status:onTick event
This commit is contained in:
+21
-30
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user