mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-03 03:38:50 +00:00
improvement(client/main): Minor optimisation - use the esx_status:onTick event
The event was added to esx_status late 2018 but never utilised anywhere; using it here drops ms to 0.0 at all times. #### Note: This event can and should also be used in various HUDs to improve performance. Many of them use 500ms threaded loops, despite status only updating every 1s by default. They also use individual event callbacks to retrieve each status value, while each value is already being sent in the 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 i=1, #data do
|
||||
if data[i].name == 'hunger' and data[i].percent == 0 then
|
||||
if prevHealth <= 150 then
|
||||
health = health - 5
|
||||
else
|
||||
health = health - 1
|
||||
end
|
||||
elseif data[i].name == 'thirst' and data[i].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