2025-06-18 00:53:24 +02:00
|
|
|
local QBCore = exports['qb-core']:GetCoreObject()
|
2025-08-11 23:31:05 +02:00
|
|
|
local isJobMenuOpen = false
|
2025-08-11 23:43:42 +02:00
|
|
|
local lastJobCheck = 0
|
|
|
|
local checkInterval = 60000 -- Check for new jobs every 60 seconds
|
2025-06-18 00:53:24 +02:00
|
|
|
|
|
|
|
local function GetJobs()
|
|
|
|
local p = promise.new()
|
|
|
|
QBCore.Functions.TriggerCallback('ps-multijob:getJobs', function(result)
|
|
|
|
p:resolve(result)
|
|
|
|
end)
|
|
|
|
return Citizen.Await(p)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function OpenUI()
|
|
|
|
local job = QBCore.Functions.GetPlayerData().job
|
2025-08-11 23:31:05 +02:00
|
|
|
SetNuiFocus(true, true)
|
|
|
|
isJobMenuOpen = true
|
2025-06-18 00:53:24 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
action = 'sendjobs',
|
|
|
|
activeJob = job["name"],
|
|
|
|
onDuty = job["onduty"],
|
|
|
|
jobs = GetJobs(),
|
|
|
|
side = Config.Side,
|
|
|
|
})
|
2025-08-11 23:43:42 +02:00
|
|
|
lastJobCheck = GetGameTimer() -- Reset the timer when we open the UI
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Function to check for job updates
|
|
|
|
local function CheckForJobUpdates()
|
|
|
|
if isJobMenuOpen and (GetGameTimer() - lastJobCheck) > checkInterval then
|
|
|
|
lastJobCheck = GetGameTimer()
|
|
|
|
local jobs = GetJobs()
|
|
|
|
SendNUIMessage({
|
|
|
|
action = 'updateJobList',
|
|
|
|
jobs = jobs
|
|
|
|
})
|
|
|
|
end
|
2025-06-18 00:53:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
RegisterNUICallback('selectjob', function(data, cb)
|
|
|
|
TriggerServerEvent("ps-multijob:changeJob", data["name"], data["grade"])
|
|
|
|
local onDuty = false
|
|
|
|
if data["name"] ~= "police" then onDuty = QBCore.Shared.Jobs[data["name"]].defaultDuty end
|
|
|
|
cb({onDuty = onDuty})
|
|
|
|
end)
|
|
|
|
|
|
|
|
RegisterNUICallback('closemenu', function(data, cb)
|
|
|
|
cb({})
|
2025-08-11 23:31:05 +02:00
|
|
|
SetNuiFocus(false, false)
|
|
|
|
isJobMenuOpen = false
|
2025-06-18 00:53:24 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
RegisterNUICallback('removejob', function(data, cb)
|
|
|
|
TriggerServerEvent("ps-multijob:removeJob", data["name"], data["grade"])
|
|
|
|
local jobs = GetJobs()
|
|
|
|
jobs[data["name"]] = nil
|
|
|
|
cb(jobs)
|
|
|
|
end)
|
|
|
|
|
|
|
|
RegisterNUICallback('toggleduty', function(data, cb)
|
|
|
|
cb({})
|
|
|
|
|
|
|
|
local job = QBCore.Functions.GetPlayerData().job.name
|
|
|
|
|
|
|
|
if Config.DenyDuty[job] then
|
|
|
|
TriggerEvent("QBCore:Notify", 'Not allowed to use this station for clock-in.', 'error')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
TriggerServerEvent("QBCore:ToggleDuty")
|
|
|
|
end)
|
|
|
|
|
|
|
|
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
|
|
|
|
SendNUIMessage({
|
|
|
|
action = 'updatejob',
|
|
|
|
name = JobInfo["name"],
|
|
|
|
label = JobInfo["label"],
|
|
|
|
onDuty = JobInfo["onduty"],
|
|
|
|
gradeLabel = JobInfo["grade"].name,
|
|
|
|
grade = JobInfo["grade"].level,
|
|
|
|
salary = JobInfo["payment"],
|
|
|
|
isWhitelist = Config.WhitelistJobs[JobInfo["name"]] or false,
|
|
|
|
description = Config.Descriptions[JobInfo["name"]] or "",
|
|
|
|
icon = Config.FontAwesomeIcons[JobInfo["name"]] or "",
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
RegisterCommand("jobmenu", OpenUI, false)
|
|
|
|
|
|
|
|
RegisterKeyMapping('jobmenu', "Show Job Management", "keyboard", "J")
|
|
|
|
|
2025-07-02 07:37:36 +02:00
|
|
|
TriggerEvent('chat:removeSuggestion', '/jobmenu')
|
|
|
|
|
|
|
|
RegisterNetEvent('ps-multijob:refreshJobs', function()
|
2025-08-11 23:31:05 +02:00
|
|
|
if isJobMenuOpen then
|
|
|
|
OpenUI() -- Refresh the UI with updated job data
|
2025-07-02 07:37:36 +02:00
|
|
|
end
|
2025-08-11 23:31:05 +02:00
|
|
|
end)
|
2025-08-11 23:43:42 +02:00
|
|
|
|
|
|
|
-- Request job updates from server periodically
|
|
|
|
Citizen.CreateThread(function()
|
|
|
|
while true do
|
|
|
|
Citizen.Wait(checkInterval)
|
|
|
|
TriggerServerEvent('ps-multijob:requestJobUpdate')
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Check for job updates while menu is open
|
|
|
|
Citizen.CreateThread(function()
|
|
|
|
while true do
|
|
|
|
Citizen.Wait(1000) -- Check every second if we need to update
|
|
|
|
CheckForJobUpdates()
|
|
|
|
end
|
|
|
|
end)
|