Skip to content

Commit

Permalink
Merge pull request #561 from bitpredator/dev
Browse files Browse the repository at this point in the history
refactor: remove jquery + Remove some shitty lines
  • Loading branch information
bitpredator authored Nov 18, 2023
2 parents 7051ba7 + 4f31f77 commit f59f81a
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 204 deletions.
4 changes: 3 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
21. [bpt_streetfight]: chore: clean up the code @bitpredator
22. [bpt_farmer]: chore: clean up the code @bitpredator
23. [bpt_teleport]: chore: clean up the code @bitpredator
24. [mythic_notify]: fix: removed unused variables @bitpredator
24. [mythic_notify]: fix: removed unused variables @bitpredator
25. [esx_status]: refactor: remove jquery + Remove some shitty lines @bitpredator
26. [esx_status/server]: fix: unused argument @bitpredator
3 changes: 1 addition & 2 deletions server-data/resources/[esx_addons]/esx_status/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ TriggerEvent('esx_status:registerStatus', name, default, color,
{remove = 200} -- Client action (add / remove) so the client can be in sync with server
)


```
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,42 @@ function CreateStatus(name, default, color, visible, tickCallback)
self.visible = visible
self.tickCallback = tickCallback

self._set = function(k, v)
function self._set(k, v)
self[k] = v
end

self._get = function(k)
function self._get(k)
return self[k]
end

self.onTick = function()
function self.onTick()
self.tickCallback(self)
end

self.set = function(val)
function self.set(val)
self.val = val
end

self.add = function(val)
function self.add(val)
if self.val + val > Config.StatusMax then
self.val = Config.StatusMax
else
self.val = self.val + val
end
end

self.remove = function(val)
function self.remove(val)
if self.val - val < 0 then
self.val = 0
else
self.val = self.val - val
end
end

self.getPercent = function()
function self.getPercent()
return (self.val / Config.StatusMax) * 100
end

return self

end
end
126 changes: 74 additions & 52 deletions server-data/resources/[esx_addons]/esx_status/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
ESX = nil
local Status, isPaused = {}, false

ESX = exports["es_extended"]:getSharedObject()

function GetStatusData(minimal)
local status = {}

Expand All @@ -19,7 +16,6 @@ function GetStatusData(minimal)
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
})
end
Expand All @@ -42,8 +38,22 @@ AddEventHandler('esx_status:unregisterStatus', function(name)
end
end)

RegisterNetEvent('esx:onPlayerLogout')
AddEventHandler('esx:onPlayerLogout', function()
ESX.PlayerLoaded = false
Status = {}
if Config.Display then
SendNUIMessage({
update = true,
status = Status
})
end
end)

RegisterNetEvent('esx_status:load')
AddEventHandler('esx_status:load', function(status)
ESX.PlayerLoaded = true
TriggerEvent('esx_status:loaded')
for i=1, #Status, 1 do
for j=1, #status, 1 do
if Status[i].name == status[j].name then
Expand All @@ -52,19 +62,35 @@ AddEventHandler('esx_status:load', function(status)
end
end

Citizen.CreateThread(function()
while true do
for i=1, #Status, 1 do
if Config.Display then TriggerEvent('esx_status:setDisplay', 0.5) end

CreateThread(function()
local data = {}
while ESX.PlayerLoaded do
for i=1, #Status do
Status[i].onTick()
table.insert(data, {
name = Status[i].name,
val = Status[i].val,
percent = (Status[i].val / 1000000) * 100
})
end

SendNUIMessage({
update = true,
status = GetStatusData()
})
if Config.Display then
local fullData = data
for i=1, #data, 1 do
fullData[i].color = Status[i].color
fullData[i].visible = Status[i].visible(Status[i])
end
SendNUIMessage({
update = true,
status = fullData
})
end

TriggerEvent('esx_status:onTick', GetStatusData(true))
Citizen.Wait(Config.TickTime)
TriggerEvent('esx_status:onTick', data)
table.wipe(data)
Wait(Config.TickTime)
end
end)
end)
Expand All @@ -77,13 +103,12 @@ AddEventHandler('esx_status:set', function(name, val)
break
end
end

SendNUIMessage({
update = true,
status = GetStatusData()
})

TriggerServerEvent('esx_status:update', GetStatusData(true))
if Config.Display then
SendNUIMessage({
update = true,
status = GetStatusData()
})
end
end)

RegisterNetEvent('esx_status:add')
Expand All @@ -94,13 +119,12 @@ AddEventHandler('esx_status:add', function(name, val)
break
end
end

SendNUIMessage({
update = true,
status = GetStatusData()
})

TriggerServerEvent('esx_status:update', GetStatusData(true))
if Config.Display then
SendNUIMessage({
update = true,
status = GetStatusData()
})
end
end)

RegisterNetEvent('esx_status:remove')
Expand All @@ -111,13 +135,12 @@ AddEventHandler('esx_status:remove', function(name, val)
break
end
end

SendNUIMessage({
update = true,
status = GetStatusData()
})

TriggerServerEvent('esx_status:update', GetStatusData(true))
if Config.Display then
SendNUIMessage({
update = true,
status = GetStatusData()
})
end
end)

AddEventHandler('esx_status:getStatus', function(name, cb)
Expand All @@ -137,30 +160,29 @@ AddEventHandler('esx_status:setDisplay', function(val)
end)

-- Pause menu disable hud display
Citizen.CreateThread(function()
while true do
Citizen.Wait(300)

if IsPauseMenuActive() and not isPaused then
if Config.Display then
AddEventHandler('esx:pauseMenuActive', function(state)
if state then
isPaused = true
TriggerEvent('esx_status:setDisplay', 0.0)
elseif not IsPauseMenuActive() and isPaused then
isPaused = false
TriggerEvent('esx_status:setDisplay', 0.5)
return
end
end
end)
isPaused = false
TriggerEvent('esx_status:setDisplay', 0.5)
end)

-- Loading screen off event
AddEventHandler('esx:loadingScreenOff', function()
TriggerEvent('esx_status:loaded')
end)
-- Loading screen off event
AddEventHandler('esx:loadingScreenOff', function()
if not isPaused then
TriggerEvent('esx_status:setDisplay', 0.3)
end
end)
end

-- Update server
Citizen.CreateThread(function()
CreateThread(function()
while true do
Citizen.Wait(Config.UpdateInterval)

TriggerServerEvent('esx_status:update', GetStatusData(true))
Wait(Config.UpdateInterval)
if ESX.PlayerLoaded then TriggerServerEvent('esx_status:update', GetStatusData(true)) end
end
end)
3 changes: 2 additions & 1 deletion server-data/resources/[esx_addons]/esx_status/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Config = {}

Config.StatusMax = 1000000
Config.TickTime = 1000
Config.UpdateInterval = 10000
Config.UpdateInterval = 30000
Config.Display = false -- Enable the esx_status bars (disable if you are using another HUD)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
USE `es_extended`;

ALTER TABLE `users` ADD COLUMN `status` LONGTEXT NULL;
ALTER TABLE `users` ADD COLUMN `status` LONGTEXT NULL;
17 changes: 8 additions & 9 deletions server-data/resources/[esx_addons]/esx_status/html/css/app.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#status_list {
visibility:hidden;
position: absolute;
left : 23;
bottom : 21%;
width : 14.5%;
opacity: 0.0;
left: 23;
bottom: 21%;
width: 14.5%;
opacity: 0;
}

.status {
padding: 1px;
margin: 0.3em;
}

.status_inner {
padding: 1px;
}

.status_val {
height : 0.5em;
height: 0.5em;
}
Loading

0 comments on commit f59f81a

Please sign in to comment.