SHARE
TWEET

Untitled

a guest Nov 16th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Status = {}
  2. local isPaused = false
  3.  
  4. function GetStatusData(minimal)
  5.     local status = {}
  6.  
  7.     for i=1, #Status, 1 do
  8.         if minimal then
  9.             table.insert(status, {
  10.                 name    = Status[i].name,
  11.                 val     = Status[i].val,
  12.                 percent = (Status[i].val / Config.StatusMax) * 100
  13.             })
  14.         else
  15.             table.insert(status, {
  16.                 name    = Status[i].name,
  17.                 val     = Status[i].val,
  18.                 color   = Status[i].color,
  19.                 visible = Status[i].visible(Status[i]),
  20.                 max     = Status[i].max,
  21.                 percent = (Status[i].val / Config.StatusMax) * 100
  22.             })
  23.         end
  24.     end
  25.  
  26.     return status
  27. end
  28.  
  29. AddEventHandler('esx_status:registerStatus', function(name, default, color, visible, tickCallback)
  30.     local status = CreateStatus(name, default, color, visible, tickCallback)
  31.     table.insert(Status, status)
  32. end)
  33.  
  34. --[[RegisterNetEvent('esx_status:load')
  35. AddEventHandler('esx_status:load', function(status)
  36.  
  37.     for i=1, #Status, 1 do
  38.         for j=1, #status, 1 do
  39.             if Status[i].name == status[j].name then
  40.                 Status[i].set(status[j].val)
  41.             end
  42.         end
  43.     end
  44.  
  45.     Citizen.CreateThread(function()
  46.       while true do
  47.  
  48.         for i=1, #Status, 1 do
  49.             Status[i].onTick()
  50.         end
  51.  
  52.             SendNUIMessage({
  53.                 update = true,
  54.                 status = GetStatusData()
  55.             })
  56.    
  57.         TriggerEvent('esx_ladderhud:updateBasics', GetStatusData(true))
  58.         Citizen.Wait(Config.TickTime)
  59.       end
  60.     end)
  61.  
  62. end)--]]
  63.  
  64. RegisterNetEvent('esx_status:load')
  65. AddEventHandler('esx_status:load', function(status)
  66.   for i=1, #Status, 1 do
  67.     for j=1, #status, 1 do
  68.         if Status[i].name == status[j].name then
  69.             Status[i].set(status[j].val)
  70.         end
  71.     end
  72.   end
  73.  
  74.   Citizen.CreateThread(function()
  75.     while true do
  76.         for i=1, #Status, 1 do
  77.             Status[i].onTick()
  78.         end
  79.  
  80.         SendNUIMessage({
  81.             update = true,
  82.             status = GetStatusData()
  83.         })
  84.  
  85.         TriggerEvent('ESX_HealthBAR-UI:updateStatus', GetStatusData(true))
  86.         Citizen.Wait(Config.TickTime)
  87.     end
  88.   end)
  89. end)
  90.  
  91. RegisterNetEvent('esx_status:set')
  92. AddEventHandler('esx_status:set', function(name, val)
  93.     for i=1, #Status, 1 do
  94.         if Status[i].name == name then
  95.             Status[i].set(val)
  96.             break
  97.         end
  98.     end
  99.  
  100.     SendNUIMessage({
  101.         update = true,
  102.         status = GetStatusData()
  103.     })
  104.  
  105.     TriggerServerEvent('esx_status:update', GetStatusData(true))
  106. end)
  107.  
  108. RegisterNetEvent('esx_status:add')
  109. AddEventHandler('esx_status:add', function(name, val)
  110.     for i=1, #Status, 1 do
  111.         if Status[i].name == name then
  112.             Status[i].add(val)
  113.             break
  114.         end
  115.     end
  116.  
  117.     SendNUIMessage({
  118.         update = true,
  119.         status = GetStatusData()
  120.     })
  121.  
  122.     TriggerServerEvent('esx_status:update', GetStatusData(true))
  123. end)
  124.  
  125. RegisterNetEvent('esx_status:remove')
  126. AddEventHandler('esx_status:remove', function(name, val)
  127.     for i=1, #Status, 1 do
  128.         if Status[i].name == name then
  129.             Status[i].remove(val)
  130.             break
  131.         end
  132.     end
  133.  
  134.     SendNUIMessage({
  135.         update = true,
  136.         status = GetStatusData()
  137.     })
  138.  
  139.     TriggerServerEvent('esx_status:update', GetStatusData(true))
  140. end)
  141.  
  142. AddEventHandler('esx_status:getStatus', function(name, cb)
  143.     for i=1, #Status, 1 do
  144.         if Status[i].name == name then
  145.             cb(Status[i])
  146.             return
  147.         end
  148.     end
  149. end)
  150.  
  151. AddEventHandler('esx_status:setDisplay', function(val)
  152.     SendNUIMessage({
  153.         setDisplay = true,
  154.         display    = val
  155.     })
  156. end)
  157.  
  158. -- Pause menu disable hud display
  159. Citizen.CreateThread(function()
  160.     while true do
  161.         Citizen.Wait(300)
  162.  
  163.         if IsPauseMenuActive() and not isPaused then
  164.             isPaused = true
  165.             TriggerEvent('esx_status:setDisplay', 0.0)
  166.         elseif not IsPauseMenuActive() and isPaused then
  167.             isPaused = false
  168.             TriggerEvent('esx_status:setDisplay', 0.5)
  169.         end
  170.     end
  171. end)
  172.  
  173. -- Loaded event
  174. Citizen.CreateThread(function()
  175.     TriggerEvent('esx_status:loaded')
  176. end)
  177.  
  178. -- Update server
  179. Citizen.CreateThread(function()
  180.     while true do
  181.         Citizen.Wait(Config.UpdateInterval)
  182.  
  183.         TriggerServerEvent('esx_status:update', GetStatusData(true))
  184.     end
  185. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top