1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-11 23:43:42 +02:00
parent aa78a2febb
commit 7dfe792351
2 changed files with 76 additions and 0 deletions

View file

@ -1,4 +1,5 @@
local QBCore = exports['qb-core']:GetCoreObject()
local jobUpdateInterval = 60000 -- 60 seconds
local function GetJobs(citizenid)
local p = promise.new()
@ -38,6 +39,12 @@ local function AddJob(citizenid, job, grade)
citizenid = citizenid,
jobdata = json.encode(jobs),
})
-- Notify the player if they're online
local Player = QBCore.Functions.GetPlayerByCitizenId(citizenid)
if Player then
TriggerClientEvent('ps-multijob:refreshJobs', Player.PlayerData.source)
end
end
exports("AddJob", AddJob)
@ -93,6 +100,12 @@ local function UpdateJobRank(citizenid, job, grade)
if Player.PlayerData.job.name == job then
UpdatePlayerJob(Player, job, grade)
end
-- Notify the player if they're online
local OnlinePlayer = QBCore.Functions.GetPlayerByCitizenId(citizenid)
if OnlinePlayer then
TriggerClientEvent('ps-multijob:refreshJobs', OnlinePlayer.PlayerData.source)
end
end
exports("UpdateJobRank", UpdateJobRank)
@ -126,6 +139,12 @@ local function RemoveJob(citizenid, job)
citizenid = citizenid,
jobdata = json.encode(jobs),
})
-- Notify the player if they're online
local OnlinePlayer = QBCore.Functions.GetPlayerByCitizenId(citizenid)
if OnlinePlayer then
TriggerClientEvent('ps-multijob:refreshJobs', OnlinePlayer.PlayerData.source)
end
end
exports("RemoveJob", RemoveJob)
@ -257,6 +276,15 @@ RegisterNetEvent("ps-multijob:removeJob",function(job, grade)
RemoveJob(Player.PlayerData.citizenid, job)
end)
-- Handle client requests for job updates
RegisterNetEvent('ps-multijob:requestJobUpdate', function()
local source = source
local Player = QBCore.Functions.GetPlayer(source)
if Player then
TriggerClientEvent('ps-multijob:refreshJobs', source)
end
end)
-- QBCORE EVENTS
RegisterNetEvent('ps-multijob:server:removeJob', function(targetCitizenId)
@ -307,3 +335,20 @@ RegisterNetEvent("jobs_creator:injectJobs", function(jobs)
end
end
end)
-- Periodically check for job updates and notify all players
Citizen.CreateThread(function()
while true do
Citizen.Wait(jobUpdateInterval)
-- Check for any job updates in the database
local Players = QBCore.Functions.GetPlayers()
for i = 1, #Players do
local Player = QBCore.Functions.GetPlayer(Players[i])
if Player then
-- This will trigger the client to refresh their job list if the menu is open
TriggerClientEvent('ps-multijob:refreshJobs', Players[i])
end
end
end
end)