Files
community_bridge/modules/framework/_default/client.lua
T
MrNewb 014dba1012 Add job count tracking to framework
Introduces job count tracking and retrieval functions to both client and server modules. The server now maintains and updates a global state of job counts, synchronizing changes to clients. Refactors job registration logic for accuracy and consistency, and adds utility functions for total job counts and player source retrieval.

This usage with the state may be a problem on initial start for highly populated servers as 200 players load in for example...
2025-08-31 22:49:31 -04:00

30 lines
881 B
Lua

---@diagnostic disable: duplicate-set-field
Framework = Framework or {}
local currentJobCounts = GlobalState.jobcounts or {}
AddStateBagChangeHandler('jobcounts', 'global', function(bagName, key, value)
if not value then currentJobCounts = {} return end
currentJobCounts = value
end)
---This is an internal function that will be used to retrieve job counts later.
---@param jobName string
---@return number
Framework.GetJobCount = function(jobName)
if not currentJobCounts[jobName] then return 0 end
return currentJobCounts[jobName]
end
---This will allow passing a table of job names and returning a sum of the total count.
---@param tbl any
---@return number
Framework.GetJobCountTotal = function(tbl)
local total = 0
for _, jobName in pairs(tbl) do
total = total + Framework.GetJobCount(jobName)
end
return total
end
return Framework