@@ -132,15 +132,21 @@ function QBCore.Functions.GetQBPlayers()
132132 return QBCore .Players
133133end
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 )
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 )
139139 local players = {}
140140 local count = 0
141141 for src , Player in pairs (QBCore .Players ) do
142- if Player .PlayerData .job .name == job then
143- if Player .PlayerData .job .onduty then
142+ local playerData = Player .PlayerData
143+ if playerData .job .name == job or playerData .job .type == job then
144+ if checkOnDuty then
145+ if playerData .job .onduty then
146+ players [# players + 1 ] = src
147+ count += 1
148+ end
149+ else
144150 players [# players + 1 ] = src
145151 count += 1
146152 end
@@ -149,18 +155,19 @@ function QBCore.Functions.GetPlayersOnDuty(job)
149155 return players , count
150156end
151157
158+ --- Gets a list of all on duty players of a specified job and the number
159+ --- @param job string
160+ --- @return table , number
161+ function QBCore .Functions .GetPlayersOnDuty (job )
162+ local players , count = QBCore .Functions .GetPlayersByJob (job , true )
163+ return players , count
164+ end
165+
152166--- Returns only the amount of players on duty for the specified job
153167--- @param job string
154168--- @return number
155169function QBCore .Functions .GetDutyCount (job )
156- local count = 0
157- for _ , Player in pairs (QBCore .Players ) do
158- if Player .PlayerData .job .name == job then
159- if Player .PlayerData .job .onduty then
160- count += 1
161- end
162- end
163- end
170+ local _ , count = QBCore .Functions .GetPlayersByJob (job , true )
164171 return count
165172end
166173
0 commit comments