Skip to content

Commit

Permalink
chore: 🎨 Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Oct 8, 2024
1 parent 9f15685 commit b8710a9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 63 deletions.
2 changes: 1 addition & 1 deletion server-data/resources/[bpt_addons]/bpt_status/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

<program> Copyright (C) 2024 bitpredator
bpt_status Copyright (C) 2024 bitpredator
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function CreateStatus(name, default, color, visible, tickCallback)
local self = {}
local self = {}

self.val = default
self.name = name
self.default = default
self.color = color
self.visible = visible
self.val = default
self.name = name
self.default = default
self.color = color
self.visible = visible
self.tickCallback = tickCallback

function self._set(k, v)
Expand Down
80 changes: 42 additions & 38 deletions server-data/resources/[bpt_addons]/bpt_status/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ function GetStatusData(minimal)
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
name = Status[i].name,
val = Status[i].val,
percent = (Status[i].val / Config.StatusMax) * 100,
})
else
table.insert(status, {
name = Status[i].name,
val = Status[i].val,
color = Status[i].color,
name = Status[i].name,
val = Status[i].val,
color = Status[i].color,
visible = Status[i].visible(Status[i]),
percent = (Status[i].val / Config.StatusMax) * 100
percent = (Status[i].val / Config.StatusMax) * 100,
})
end
end

return status
end

AddEventHandler('bpt_status:registerStatus', function(name, default, color, visible, tickCallback)
AddEventHandler("bpt_status:registerStatus", function(name, default, color, visible, tickCallback)
local status = CreateStatus(name, default, color, visible, tickCallback)

for i = 1, #OriginalStatus, 1 do
Expand All @@ -36,7 +36,7 @@ AddEventHandler('bpt_status:registerStatus', function(name, default, color, visi
table.insert(Status, status)
end)

AddEventHandler('bpt_status:unregisterStatus', function(name)
AddEventHandler("bpt_status:unregisterStatus", function(name)
for k, v in ipairs(Status) do
if v.name == name then
table.remove(Status, k)
Expand All @@ -45,25 +45,27 @@ AddEventHandler('bpt_status:unregisterStatus', function(name)
end
end)

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

RegisterNetEvent('bpt_status:load')
AddEventHandler('bpt_status:load', function(status)
RegisterNetEvent("bpt_status:load")
AddEventHandler("bpt_status:load", function(status)
OriginalStatus = status
ESX.PlayerLoaded = true
TriggerEvent('bpt_status:loaded')
TriggerEvent("bpt_status:loaded")

if Config.Display then TriggerEvent('bpt_status:setDisplay', 0.5) end
if Config.Display then
TriggerEvent("bpt_status:setDisplay", 0.5)
end

CreateThread(function()
local data = {}
Expand All @@ -73,7 +75,7 @@ AddEventHandler('bpt_status:load', function(status)
table.insert(data, {
name = Status[i].name,
val = Status[i].val,
percent = (Status[i].val / Config.StatusMax) * 100
percent = (Status[i].val / Config.StatusMax) * 100,
})
end

Expand All @@ -85,19 +87,19 @@ AddEventHandler('bpt_status:load', function(status)
end
SendNUIMessage({
update = true,
status = fullData
status = fullData,
})
end

TriggerEvent('bpt_status:onTick', data)
TriggerEvent("bpt_status:onTick", data)
table.wipe(data)
Wait(Config.TickTime)
end
end)
end)

RegisterNetEvent('bpt_status:set')
AddEventHandler('bpt_status:set', function(name, val)
RegisterNetEvent("bpt_status:set")
AddEventHandler("bpt_status:set", function(name, val)
for i = 1, #Status, 1 do
if Status[i].name == name then
Status[i].set(val)
Expand All @@ -107,13 +109,13 @@ AddEventHandler('bpt_status:set', function(name, val)
if Config.Display then
SendNUIMessage({
update = true,
status = GetStatusData()
status = GetStatusData(),
})
end
end)

RegisterNetEvent('bpt_status:add')
AddEventHandler('bpt_status:add', function(name, val)
RegisterNetEvent("bpt_status:add")
AddEventHandler("bpt_status:add", function(name, val)
for i = 1, #Status, 1 do
if Status[i].name == name then
Status[i].add(val)
Expand All @@ -123,13 +125,13 @@ AddEventHandler('bpt_status:add', function(name, val)
if Config.Display then
SendNUIMessage({
update = true,
status = GetStatusData()
status = GetStatusData(),
})
end
end)

RegisterNetEvent('bpt_status:remove')
AddEventHandler('bpt_status:remove', function(name, val)
RegisterNetEvent("bpt_status:remove")
AddEventHandler("bpt_status:remove", function(name, val)
for i = 1, #Status, 1 do
if Status[i].name == name then
Status[i].remove(val)
Expand All @@ -139,12 +141,12 @@ AddEventHandler('bpt_status:remove', function(name, val)
if Config.Display then
SendNUIMessage({
update = true,
status = GetStatusData()
status = GetStatusData(),
})
end
end)

AddEventHandler('bpt_status:getStatus', function(name, cb)
AddEventHandler("bpt_status:getStatus", function(name, cb)
for i = 1, #Status, 1 do
if Status[i].name == name then
cb(Status[i])
Expand All @@ -153,33 +155,33 @@ AddEventHandler('bpt_status:getStatus', function(name, cb)
end
end)

AddEventHandler('bpt_status:getAllStatus', function(cb)
AddEventHandler("bpt_status:getAllStatus", function(cb)
cb(Status)
end)

AddEventHandler('bpt_status:setDisplay', function(val)
AddEventHandler("bpt_status:setDisplay", function(val)
SendNUIMessage({
setDisplay = true,
display = val
display = val,
})
end)

-- Pause menu disable hud display
if Config.Display then
AddEventHandler('esx:pauseMenuActive', function(state)
AddEventHandler("esx:pauseMenuActive", function(state)
if state then
isPaused = true
TriggerEvent('bpt_status:setDisplay', 0.0)
TriggerEvent("bpt_status:setDisplay", 0.0)
return
end
isPaused = false
TriggerEvent('bpt_status:setDisplay', 0.5)
TriggerEvent("bpt_status:setDisplay", 0.5)
end)

-- Loading screen off event
AddEventHandler('esx:loadingScreenOff', function()
AddEventHandler("esx:loadingScreenOff", function()
if not isPaused then
TriggerEvent('bpt_status:setDisplay', 0.3)
TriggerEvent("bpt_status:setDisplay", 0.3)
end
end)
end
Expand All @@ -188,6 +190,8 @@ end
CreateThread(function()
while true do
Wait(Config.UpdateInterval)
if ESX.PlayerLoaded then TriggerServerEvent('bpt_status:update', GetStatusData(true)) end
if ESX.PlayerLoaded then
TriggerServerEvent("bpt_status:update", GetStatusData(true))
end
end
end)
8 changes: 4 additions & 4 deletions server-data/resources/[bpt_addons]/bpt_status/config.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Config = {}
Config = {}

Config.StatusMax = 1000000
Config.TickTime = 1000
Config.StatusMax = 1000000
Config.TickTime = 1000
Config.UpdateInterval = 30000
Config.Display = false -- Enable the bpt_status bars (disable if you are using another HUD)
Config.Display = false -- Enable the bpt_status bars (disable if you are using another HUD)
28 changes: 14 additions & 14 deletions server-data/resources/[bpt_addons]/bpt_status/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
local function setPlayerStatus(xPlayer, data)
data = data and json.decode(data) or {}

xPlayer.set('status', data)
xPlayer.set("status", data)
ESX.Players[xPlayer.source] = data
TriggerClientEvent('bpt_status:load', xPlayer.source, data)
TriggerClientEvent("bpt_status:load", xPlayer.source, data)
end

AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
AddEventHandler("onResourceStart", function(resourceName)
if GetCurrentResourceName() ~= resourceName then
return
end

for _, xPlayer in pairs(ESX.Players) do
MySQL.scalar('SELECT status FROM users WHERE identifier = ?', { xPlayer.identifier }, function(result)
MySQL.scalar("SELECT status FROM users WHERE identifier = ?", { xPlayer.identifier }, function(result)
setPlayerStatus(xPlayer, result)
end)
end
end)

AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
MySQL.scalar('SELECT status FROM users WHERE identifier = ?', { xPlayer.identifier }, function(result)
AddEventHandler("esx:playerLoaded", function(playerId, xPlayer)
MySQL.scalar("SELECT status FROM users WHERE identifier = ?", { xPlayer.identifier }, function(result)
setPlayerStatus(xPlayer, result)
end)
end)

AddEventHandler('esx:playerDropped', function(playerId, reason)
AddEventHandler("esx:playerDropped", function(playerId, reason)
local xPlayer = ESX.GetPlayerFromId(playerId)
local status = ESX.Players[xPlayer.source]

MySQL.update('UPDATE users SET status = ? WHERE identifier = ?', { json.encode(status), xPlayer.identifier })
MySQL.update("UPDATE users SET status = ? WHERE identifier = ?", { json.encode(status), xPlayer.identifier })
ESX.Players[xPlayer.source] = nil
end)

AddEventHandler('bpt_status:getStatus', function(playerId, statusName, cb)
AddEventHandler("bpt_status:getStatus", function(playerId, statusName, cb)
local status = ESX.Players[playerId]
for i = 1, #status do
if status[i].name == statusName then
Expand All @@ -41,11 +41,11 @@ AddEventHandler('bpt_status:getStatus', function(playerId, statusName, cb)
end
end)

RegisterServerEvent('bpt_status:update')
AddEventHandler('bpt_status:update', function(status)
RegisterServerEvent("bpt_status:update")
AddEventHandler("bpt_status:update", function(status)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.set('status', status) -- save to xPlayer for compatibility
xPlayer.set("status", status) -- save to xPlayer for compatibility
ESX.Players[xPlayer.source] = status -- save locally for performance
end
end)
Expand All @@ -61,7 +61,7 @@ CreateThread(function()
end
end
if #parameters > 0 then
MySQL.prepare('UPDATE users SET status = ? WHERE identifier = ?', parameters)
MySQL.prepare("UPDATE users SET status = ? WHERE identifier = ?", parameters)
end
end
end)

0 comments on commit b8710a9

Please sign in to comment.