diff --git a/server-data/resources/[bpt_addons]/bpt_status/LICENSE b/server-data/resources/[bpt_addons]/bpt_status/LICENSE index 62f066311..144a34228 100644 --- a/server-data/resources/[bpt_addons]/bpt_status/LICENSE +++ b/server-data/resources/[bpt_addons]/bpt_status/LICENSE @@ -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: - 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. diff --git a/server-data/resources/[bpt_addons]/bpt_status/client/classes/status.lua b/server-data/resources/[bpt_addons]/bpt_status/client/classes/status.lua index 55ae9738b..6476a2ce6 100644 --- a/server-data/resources/[bpt_addons]/bpt_status/client/classes/status.lua +++ b/server-data/resources/[bpt_addons]/bpt_status/client/classes/status.lua @@ -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) diff --git a/server-data/resources/[bpt_addons]/bpt_status/client/main.lua b/server-data/resources/[bpt_addons]/bpt_status/client/main.lua index b4eed4bc6..da26e6b38 100644 --- a/server-data/resources/[bpt_addons]/bpt_status/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_status/client/main.lua @@ -6,17 +6,17 @@ 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 @@ -24,7 +24,7 @@ function GetStatusData(minimal) 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 @@ -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) @@ -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 = {} @@ -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 @@ -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) @@ -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) @@ -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) @@ -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]) @@ -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 @@ -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) diff --git a/server-data/resources/[bpt_addons]/bpt_status/config.lua b/server-data/resources/[bpt_addons]/bpt_status/config.lua index 75a442afb..3328c6d28 100644 --- a/server-data/resources/[bpt_addons]/bpt_status/config.lua +++ b/server-data/resources/[bpt_addons]/bpt_status/config.lua @@ -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) diff --git a/server-data/resources/[bpt_addons]/bpt_status/server/main.lua b/server-data/resources/[bpt_addons]/bpt_status/server/main.lua index 2d3e1590b..b77bf2087 100644 --- a/server-data/resources/[bpt_addons]/bpt_status/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_status/server/main.lua @@ -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 @@ -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) @@ -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)