Skip to content
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

Fix qb-core jobs counter #18

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
27 changes: 21 additions & 6 deletions resource/server/framework.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ local jobs = {
onDuty = onDuty,
}

if onDuty then self.add(data.name) end
if onDuty then
self.add(data.name)
end
end,

---@param data JobData
Expand All @@ -54,19 +56,24 @@ local jobs = {
onDuty = onDuty,
}

if onDuty then self.add(data.name) end
if lastJob.onDuty then self.remove(lastJob.name) end
if onDuty then
self.add(data.name)
end
if lastJob.onDuty then
self.remove(lastJob.name)
end
end
}

AddEventHandler('playerDropped', function()
local lastJob = players[source]
players[source] = nil

if lastJob?.onDuty then jobs.remove(lastJob.name) end
if lastJob?.onDuty then
jobs.remove(lastJob.name)
end
end)


if core == 'esx' then
-- Credits to Linden (https://gist.github.com/thelindat/93311a4fd6ea6c1d4427438a533e228c)
local ESX = exports.es_extended:getSharedObject()
Expand Down Expand Up @@ -116,12 +123,20 @@ elseif core == 'qb' then
})
end)

AddEventHandler('QBCore:Server:OnPlayerUnload', function(source)
local lastJob = players[source]
players[source] = nil

if lastJob?.onDuty then
jobs.remove(lastJob.name)
end
end)

AddEventHandler('QBCore:Player:SetPlayerData', function(player)
jobs:update({
name = player.job.name,
onDuty = player.job.onduty,
source = player.source
})
end)

end