forked from Simnation/Main
ed
This commit is contained in:
parent
aa78a2febb
commit
7dfe792351
2 changed files with 76 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
local isJobMenuOpen = false
|
local isJobMenuOpen = false
|
||||||
|
local lastJobCheck = 0
|
||||||
|
local checkInterval = 60000 -- Check for new jobs every 60 seconds
|
||||||
|
|
||||||
local function GetJobs()
|
local function GetJobs()
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
|
@ -20,6 +22,19 @@ local function OpenUI()
|
||||||
jobs = GetJobs(),
|
jobs = GetJobs(),
|
||||||
side = Config.Side,
|
side = Config.Side,
|
||||||
})
|
})
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNUICallback('selectjob', function(data, cb)
|
RegisterNUICallback('selectjob', function(data, cb)
|
||||||
|
@ -81,3 +96,19 @@ RegisterNetEvent('ps-multijob:refreshJobs', function()
|
||||||
OpenUI() -- Refresh the UI with updated job data
|
OpenUI() -- Refresh the UI with updated job data
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- 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)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
local jobUpdateInterval = 60000 -- 60 seconds
|
||||||
|
|
||||||
local function GetJobs(citizenid)
|
local function GetJobs(citizenid)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
|
@ -38,6 +39,12 @@ local function AddJob(citizenid, job, grade)
|
||||||
citizenid = citizenid,
|
citizenid = citizenid,
|
||||||
jobdata = json.encode(jobs),
|
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
|
end
|
||||||
exports("AddJob", AddJob)
|
exports("AddJob", AddJob)
|
||||||
|
|
||||||
|
@ -93,6 +100,12 @@ local function UpdateJobRank(citizenid, job, grade)
|
||||||
if Player.PlayerData.job.name == job then
|
if Player.PlayerData.job.name == job then
|
||||||
UpdatePlayerJob(Player, job, grade)
|
UpdatePlayerJob(Player, job, grade)
|
||||||
end
|
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
|
end
|
||||||
exports("UpdateJobRank", UpdateJobRank)
|
exports("UpdateJobRank", UpdateJobRank)
|
||||||
|
|
||||||
|
@ -126,6 +139,12 @@ local function RemoveJob(citizenid, job)
|
||||||
citizenid = citizenid,
|
citizenid = citizenid,
|
||||||
jobdata = json.encode(jobs),
|
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
|
end
|
||||||
exports("RemoveJob", RemoveJob)
|
exports("RemoveJob", RemoveJob)
|
||||||
|
|
||||||
|
@ -257,6 +276,15 @@ RegisterNetEvent("ps-multijob:removeJob",function(job, grade)
|
||||||
RemoveJob(Player.PlayerData.citizenid, job)
|
RemoveJob(Player.PlayerData.citizenid, job)
|
||||||
end)
|
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
|
-- QBCORE EVENTS
|
||||||
|
|
||||||
RegisterNetEvent('ps-multijob:server:removeJob', function(targetCitizenId)
|
RegisterNetEvent('ps-multijob:server:removeJob', function(targetCitizenId)
|
||||||
|
@ -307,3 +335,20 @@ RegisterNetEvent("jobs_creator:injectJobs", function(jobs)
|
||||||
end
|
end
|
||||||
end
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue