mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 01:38:52 +00:00
Performance, respect EnableHud from ESX
This commit is contained in:
+27
-46
@@ -1,46 +1,38 @@
|
||||
local Status = {}
|
||||
local isPaused = false
|
||||
|
||||
function GetStatusData(minimal)
|
||||
|
||||
local status = {}
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
|
||||
if minimal then
|
||||
|
||||
table.insert(status, {
|
||||
name = Status[i].name,
|
||||
val = Status[i].val,
|
||||
percent = (Status[i].val / Config.StatusMax) * 100,
|
||||
percent = (Status[i].val / Config.StatusMax) * 100
|
||||
})
|
||||
|
||||
else
|
||||
|
||||
table.insert(status, {
|
||||
name = Status[i].name,
|
||||
val = Status[i].val,
|
||||
color = Status[i].color,
|
||||
visible = Status[i].visible(Status[i]),
|
||||
max = Status[i].max,
|
||||
percent = (Status[i].val / Config.StatusMax) * 100,
|
||||
percent = (Status[i].val / Config.StatusMax) * 100
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return status
|
||||
|
||||
end
|
||||
|
||||
AddEventHandler('esx_status:registerStatus', function(name, default, color, visible, tickCallback)
|
||||
local s = CreateStatus(name, default, color, visible, tickCallback)
|
||||
table.insert(Status, s)
|
||||
local status = CreateStatus(name, default, color, visible, tickCallback)
|
||||
table.insert(Status, status)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_status:load')
|
||||
AddEventHandler('esx_status:load', function(status)
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
for j=1, #status, 1 do
|
||||
if Status[i].name == status[j].name then
|
||||
@@ -50,27 +42,23 @@ AddEventHandler('esx_status:load', function(status)
|
||||
end
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
Status[i].onTick()
|
||||
end
|
||||
while true do
|
||||
for i=1, #Status, 1 do
|
||||
Status[i].onTick()
|
||||
end
|
||||
|
||||
SendNUIMessage({
|
||||
update = true,
|
||||
status = GetStatusData()
|
||||
})
|
||||
|
||||
Citizen.Wait(Config.TickTime)
|
||||
|
||||
end
|
||||
Citizen.Wait(Config.TickTime)
|
||||
end
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_status:set')
|
||||
AddEventHandler('esx_status:set', function(name, val)
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
if Status[i].name == name then
|
||||
Status[i].set(val)
|
||||
@@ -84,12 +72,10 @@ AddEventHandler('esx_status:set', function(name, val)
|
||||
})
|
||||
|
||||
TriggerServerEvent('esx_status:update', GetStatusData(true))
|
||||
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_status:add')
|
||||
AddEventHandler('esx_status:add', function(name, val)
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
if Status[i].name == name then
|
||||
Status[i].add(val)
|
||||
@@ -103,12 +89,10 @@ AddEventHandler('esx_status:add', function(name, val)
|
||||
})
|
||||
|
||||
TriggerServerEvent('esx_status:update', GetStatusData(true))
|
||||
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_status:remove')
|
||||
AddEventHandler('esx_status:remove', function(name, val)
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
if Status[i].name == name then
|
||||
Status[i].remove(val)
|
||||
@@ -122,44 +106,40 @@ AddEventHandler('esx_status:remove', function(name, val)
|
||||
})
|
||||
|
||||
TriggerServerEvent('esx_status:update', GetStatusData(true))
|
||||
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:getStatus', function(name, cb)
|
||||
|
||||
for i=1, #Status, 1 do
|
||||
if Status[i].name == name then
|
||||
cb(Status[i])
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:setDisplay', function(val)
|
||||
|
||||
SendNUIMessage({
|
||||
setDisplay = true,
|
||||
display = val
|
||||
})
|
||||
|
||||
end)
|
||||
|
||||
-- Pause menu disable hud display
|
||||
local isPaused = false
|
||||
if ESX.GetConfig().EnableHud then
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(300)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(10)
|
||||
if IsPauseMenuActive() and not isPaused then
|
||||
isPaused = true
|
||||
TriggerEvent('esx_status:setDisplay', 0.0)
|
||||
elseif not IsPauseMenuActive() and isPaused then
|
||||
isPaused = false
|
||||
TriggerEvent('esx_status:setDisplay', 0.5)
|
||||
end
|
||||
end
|
||||
end)
|
||||
if IsPauseMenuActive() and not isPaused then
|
||||
isPaused = true
|
||||
TriggerEvent('esx_status:setDisplay', 0.0)
|
||||
elseif not IsPauseMenuActive() and isPaused then
|
||||
isPaused = false
|
||||
TriggerEvent('esx_status:setDisplay', 0.5)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Loaded event
|
||||
Citizen.CreateThread(function()
|
||||
@@ -170,6 +150,7 @@ end)
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(Config.UpdateInterval)
|
||||
|
||||
TriggerServerEvent('esx_status:update', GetStatusData(true))
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user