Skip to content

feat(core): add functions to retrieve online players by job name or type with optional on-duty check #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,52 @@ function QBCore.Functions.GetPlayersOnDuty(job)
return players, count
end

---Gets a list of all online players of a specified job and the number, with an option to check if they are on duty.
---@param job string
---@param checkOnDuty boolean
---@return table, number
function QBCore.Functions.GetPlayersByJobName(job, checkOnDuty)
local players = {}
local count = 0
for src, Player in pairs(QBCore.Players) do
if Player.PlayerData.job.name == job then
if checkOnDuty then
if Player.PlayerData.job.onduty then
players[#players + 1] = src
count += 1
end
else
players[#players + 1] = src
count += 1
end
end
end
return players, count
end

---Gets a list of all online players with a specified job type and the number, with an option to check if they are on duty.
---@param jobType string
---@param checkOnDuty boolean
---@return table, number
function QBCore.Functions.GetPlayersByJobType(jobType, checkOnDuty)
local players = {}
local count = 0
for src, Player in pairs(QBCore.Players) do
if Player.PlayerData.job.type == jobType then
if checkOnDuty then
if Player.PlayerData.job.onduty then
players[#players + 1] = src
count += 1
end
else
players[#players + 1] = src
count += 1
end
end
end
return players, count
end

---Returns only the amount of players on duty for the specified job
---@param job string
---@return number
Expand Down
Loading