@@ -132,15 +132,21 @@ function QBCore.Functions.GetQBPlayers()
132
132
return QBCore .Players
133
133
end
134
134
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 )
139
139
local players = {}
140
140
local count = 0
141
141
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
144
150
players [# players + 1 ] = src
145
151
count += 1
146
152
end
@@ -149,18 +155,19 @@ function QBCore.Functions.GetPlayersOnDuty(job)
149
155
return players , count
150
156
end
151
157
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
+
152
166
--- Returns only the amount of players on duty for the specified job
153
167
--- @param job string
154
168
--- @return number
155
169
function 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 )
164
171
return count
165
172
end
166
173
0 commit comments