Skip to content

Commit d19f34b

Browse files
committed
update
1 parent 2827a63 commit d19f34b

File tree

1 file changed

+12
-51
lines changed

1 file changed

+12
-51
lines changed

server/functions.lua

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,17 @@ function QBCore.Functions.GetQBPlayers()
132132
return QBCore.Players
133133
end
134134

135-
---Gets a list of all on duty players of a specified job and the number
136-
---@param job string
137-
---@return table, number
138-
function QBCore.Functions.GetPlayersOnDuty(job)
139-
local players = {}
140-
local count = 0
141-
for src, Player in pairs(QBCore.Players) do
142-
if Player.PlayerData.job.name == job then
143-
if Player.PlayerData.job.onduty then
144-
players[#players + 1] = src
145-
count += 1
146-
end
147-
end
148-
end
149-
return players, count
150-
end
151-
152-
---Gets a list of all online players of a specified job and the number, with an option to check if they are on duty.
153-
---@param job string
154-
---@param checkOnDuty boolean
155-
---@return table, number
156-
function QBCore.Functions.GetPlayersByJobName(job, checkOnDuty)
135+
--- Gets a list of all online players of a specified job or job type and the number
136+
--- @param job string
137+
--- @param checkOnDuty boolean If true, only players on duty will be returned
138+
function QBCore.Functions.GetPlayersByJob(job, checkOnDuty)
157139
local players = {}
158140
local count = 0
159141
for src, Player in pairs(QBCore.Players) do
160-
if Player.PlayerData.job.name == job then
142+
local playerData = Player.PlayerData
143+
if playerData.job.name == job or playerData.job.type == job then
161144
if checkOnDuty then
162-
if Player.PlayerData.job.onduty then
145+
if playerData.job.onduty then
163146
players[#players + 1] = src
164147
count += 1
165148
end
@@ -172,41 +155,19 @@ function QBCore.Functions.GetPlayersByJobName(job, checkOnDuty)
172155
return players, count
173156
end
174157

175-
---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.
176-
---@param jobType string
177-
---@param checkOnDuty boolean
158+
---Gets a list of all on duty players of a specified job and the number
159+
---@param job string
178160
---@return table, number
179-
function QBCore.Functions.GetPlayersByJobType(jobType, checkOnDuty)
180-
local players = {}
181-
local count = 0
182-
for src, Player in pairs(QBCore.Players) do
183-
if Player.PlayerData.job.type == jobType then
184-
if checkOnDuty then
185-
if Player.PlayerData.job.onduty then
186-
players[#players + 1] = src
187-
count += 1
188-
end
189-
else
190-
players[#players + 1] = src
191-
count += 1
192-
end
193-
end
194-
end
161+
function QBCore.Functions.GetPlayersOnDuty(job)
162+
local players, count = QBCore.Functions.GetPlayersByJob(job, true)
195163
return players, count
196164
end
197165

198166
---Returns only the amount of players on duty for the specified job
199167
---@param job string
200168
---@return number
201169
function QBCore.Functions.GetDutyCount(job)
202-
local count = 0
203-
for _, Player in pairs(QBCore.Players) do
204-
if Player.PlayerData.job.name == job then
205-
if Player.PlayerData.job.onduty then
206-
count += 1
207-
end
208-
end
209-
end
170+
local _, count = QBCore.Functions.GetPlayersByJob(job, true)
210171
return count
211172
end
212173

0 commit comments

Comments
 (0)