Files
esx_core/client/main.lua
T
Jérémie N'gadi 1dfeee2a18 Increase TickTime
2017-08-23 10:17:58 +02:00

97 lines
1.7 KiB
Lua

local Status = {}
local loaded = false
RegisterNetEvent('esx_status:update')
AddEventHandler('esx_status:update', function(status)
Status = status
SendNUIMessage({
update = true,
status = Status
})
if not loaded then
TriggerEvent('esx_status:loaded')
loaded = true
end
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)
-- Calculate status
Citizen.CreateThread(function()
while true do
for i=1, #Status, 1 do
if Status[i].clientAction.add ~= nil then
local val = math.floor(Status[i].clientAction.add / (Config.TickTime / Config.ClientTickTime))
if Status[i].val + val > Config.StatusMax then
Status[i].val = StatusMax
else
Status[i].val = Status[i].val + val
end
end
if Status[i].clientAction.remove ~= nil then
local val = math.floor(Status[i].clientAction.remove / (Config.TickTime / Config.ClientTickTime))
if Status[i].val - val < 0 then
Status[i].val = 0
else
Status[i].val = Status[i].val - val
end
end
end
SendNUIMessage({
update = true,
status = Status
})
Citizen.Wait(Config.ClientqTickTime)
end
end)
-- Pause menu disable hud display
local isPaused = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
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)