From 2236163d5ca5397cc7dc6709c843ae35a8ec53ce Mon Sep 17 00:00:00 2001 From: Mojito-Fivem Date: Sun, 7 Nov 2021 22:44:39 +0000 Subject: [PATCH 1/3] feat(server/functions): GetPlayersOnDuty Co-authored-by: Solositeous <36283056+Solositeous@users.noreply.github.com> --- server/functions.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index 2f78ebf..ec98de6 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -76,6 +76,22 @@ end function QBCore.Functions.GetQBPlayers() return QBCore.Players end + +function QBCore.Functions.GetPlayersOnDuty(job) + local players = {} + local count = 0 + + for src, Player in pairs(QBCore.Players) do + if Player.PlayerData.job.name == job then + if Player.PlayerData.job.onduty then + players[#players + 1] = src + count = count + 1 + end + end + end + return players, count +end + -- Paychecks (standalone - don't touch) function PaycheckLoop() From 85819bddbfbfbf1522352aae2932366560821dd3 Mon Sep 17 00:00:00 2001 From: Mojito-Fivem Date: Sun, 7 Nov 2021 22:46:00 +0000 Subject: [PATCH 2/3] feat(server/functions): GetDutyCount --- server/functions.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index ec98de6..34df851 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -92,6 +92,19 @@ function QBCore.Functions.GetPlayersOnDuty(job) return players, count end +function QBCore.Functions.GetDutyCount(job) + local count = 0 + + for _, Player in pairs(QBCore.Players) do + if Player.PlayerData.job.name == job then + if Player.PlayerData.job.onduty then + count = count + 1 + end + end + end + return count +end + -- Paychecks (standalone - don't touch) function PaycheckLoop() From 21d85a63ecce03cec0866a9868b49b2ff495382a Mon Sep 17 00:00:00 2001 From: Mojito-Fivem Date: Sun, 7 Nov 2021 22:47:39 +0000 Subject: [PATCH 3/3] chore(server/functions): Add Comments for GetDuty functions --- server/functions.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index 34df851..1ff1e71 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -77,6 +77,7 @@ function QBCore.Functions.GetQBPlayers() return QBCore.Players end +--- Gets a list of all on duty players of a specified job and the number function QBCore.Functions.GetPlayersOnDuty(job) local players = {} local count = 0 @@ -92,6 +93,7 @@ function QBCore.Functions.GetPlayersOnDuty(job) return players, count end +-- Returns only the amount of players on duty for the specified job function QBCore.Functions.GetDutyCount(job) local count = 0