From 37b855d7a73dd035726c002ee289ad4027c892bf Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 2 May 2025 11:20:09 +0100 Subject: [PATCH] Better syncing of onDuty variable Added a check to the script start to get the current players duty (helpful if yours saves the duty through restarts) Also added core specific triggers for job/duty changes to help keep these in sync --- shared/jobfunctions.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/shared/jobfunctions.lua b/shared/jobfunctions.lua index 4cc9722..83b3dc1 100644 --- a/shared/jobfunctions.lua +++ b/shared/jobfunctions.lua @@ -12,7 +12,9 @@ ------------------------------------------------------------- -- Global Duty Status ------------------------------------------------------------- -onDuty = false +-- This attempts to sync up with the players framework onDuty variable +-- This stops the script getting confused when one is false and one is true +onDuty = not isServer() and getPlayer().onDuty or false ------------------------------------------------------------- -- Boss Role Detection @@ -92,11 +94,14 @@ end --- toggleDuty() -- Player receives a notification of their new duty status. --- ``` function toggleDuty() - onDuty = not onDuty if isStarted(QBExport) or isStarted(QBXExport) then TriggerServerEvent("QBCore:ToggleDuty") + Wait(100) + onDuty = getPlayer().onDuty elseif isStarted(RSGExport) then TriggerServerEvent("RSGCore:ToggleDuty") + Wait(100) + onDuty = getPlayer().onDuty else if onDuty then triggerNotify(nil, "Now on duty", "success") @@ -106,6 +111,15 @@ function toggleDuty() end end +-- Framework specific functions to keep duty status synced +RegisterNetEvent("QBCore:Client:OnJobUpdate", function(JobInfo) onDuty = JobInfo.onduty end) +RegisterNetEvent("QBCore:Client:SetDuty", function(duty) onDuty = duty end) + +RegisterNetEvent("qbx_core:client:onJobUpdate", function(JobInfo) onDuty = JobInfo.onduty end) + +RegisterNetEvent("RSGCore:Client:OnJobUpdate", function(JobInfo) onDuty = JobInfo.onduty end) +RegisterNetEvent("RSGCore:Client:SetDuty", function(duty) onDuty = duty end) + ------------------------------------------------------------- -- Interaction Functions -------------------------------------------------------------