draft GetPlayerSourcesByJob

This commit is contained in:
MrNewb committed 2025-08-07 00:47:51 -04:00
1 parent 140bad5b34
commit b1556d13fb
4 files changed
+60 -30

No files matched your search

+53
View File
@@ -1,3 +1,56 @@
Framework = Framework or {}
local jobsRegisteredTable = {}
local invertedJobsRegisteredTable = {}
---This is an internal function that will be used to retrieve job counts later.
---@param jobName string
---@return number
Framework.GetJobCount = function(jobName)
return #jobsRegisteredTable[jobName] or 0
end
---This will return a list of player sources for a given job.
---@param jobName string
---@return table
Framework.GetPlayerSourcesByJob = function(jobName)
if not jobsRegisteredTable[jobName] then return {} end
return jobsRegisteredTable[jobName]
end
---This will update the cached tables for job counts.
---This is used to track how many players are in a job.
---@param src number
---@param jobName string
Framework.AddJobCount = function(src, jobName)
if not jobsRegisteredTable[jobName] then jobsRegisteredTable[jobName] = {} end
if jobsRegisteredTable[jobName][src] then return false end
jobsRegisteredTable[jobName][src] = true
invertedJobsRegisteredTable[src] = jobName
return true, #jobsRegisteredTable[jobName]
end
---This will return the job name for a given source.
---This is an internal function that will be used to retrieve job names in situations where player data is unavailable.
---@param src number
Framework.SearchJobCountBySource = function(src)
if not invertedJobsRegisteredTable[src] then return nil end
return invertedJobsRegisteredTable[src]
end
---This will remove the job count for a given source.
---@param src number
---@param jobName string | nil
Framework.RemoveJobCount = function(src, jobName)
if not jobName then
jobName = Framework.SearchJobCountBySource(src)
end
if not jobName then return false end
if not jobsRegisteredTable[jobName] then return false end
if not jobsRegisteredTable[jobName][src] then return false end
invertedJobsRegisteredTable[src] = nil
jobsRegisteredTable[jobName][src] = nil
return true, #jobsRegisteredTable[jobName]
end
return Framework
+3 -11
View File
@@ -336,18 +336,10 @@ Framework.SetPlayerDuty = function(src, status)
end
---This will get a table of player sources that have the specified job name.
---@param job any
---@param job string
---@return table
Framework.GetPlayersByJob = function(job)
local players = GetPlayers()
local playerList = {}
for _, src in pairs(players) do
local xPlayer = Framework.GetPlayer(src)
if xPlayer and xPlayer.getJob().name == job then
table.insert(playerList, src)
end
end
return playerList
return Framework.GetPlayerSourcesByJob(job) or {}
end
-- Sets the player's job to the specified name and grade.
@@ -363,7 +355,7 @@ Framework.SetPlayerJob = function(src, name, grade)
return
end
xPlayer.setJob(name, grade, true)
return true
return true
end
---This will add money based on the type of account (money/bank)
+2 -10
View File
@@ -361,18 +361,10 @@ Framework.GetPlayerGang = function(src)
end
---This will get a table of player sources that have the specified job name.
---@param job any
---@param job string
---@return table
Framework.GetPlayersByJob = function(job)
local playerList = {}
local players = QBCore.Functions.GetPlayers()
for _, src in pairs(players) do
local player = Framework.GetPlayer(src).PlayerData
if player.job.name == job then
table.insert(playerList, src)
end
end
return playerList
return Framework.GetPlayerSourcesByJob(job) or {}
end
---Depricated: Returns the job name, label, grade name, and grade level of the player.
+2 -9
View File
@@ -286,18 +286,11 @@ Framework.GetPlayerGang = function(src)
return player.gang.name
end
---This will return a table of all players with the specified job.
---This will get a table of player sources that have the specified job name.
---@param job string
---@return table
Framework.GetPlayersByJob = function(job)
local playerList = {}
local players = QBox:GetQBPlayers()
for src, player in pairs(players) do
if player.PlayerData.job.name == job then
table.insert(playerList, src)
end
end
return playerList
return Framework.GetPlayerSourcesByJob(job) or {}
end
---Depricated: Returns the job name, label, grade name, and grade level of the player.