Files
Elite-Gaming-FiveM/resources/[ERS]/night_ers/callouts/callouts_server.lua
T
2025-08-21 07:59:16 -07:00

81 lines
3.5 KiB
Lua

--============================== BUILD CALLOUTS =================================--
local BuildCalloutQueue = {}
local processingBuildCalloutQueue = false
RegisterServerEvent(Config.EventPrefix..':buildCallout')
AddEventHandler(Config.EventPrefix..':buildCallout', function(calloutData)
local src = source
table.insert(BuildCalloutQueue, {src = src, calloutData = calloutData})
processBuildCalloutQueue()
end)
function processBuildCalloutQueue()
if processingBuildCalloutQueue or #BuildCalloutQueue == 0 then
return
end
processingBuildCalloutQueue = true
local request = table.remove(BuildCalloutQueue, 1)
local src = request.src
local calloutData = request.calloutData
local calloutBuilt = false
local pedList = {}
local vehicleList = {}
local objectList = {}
local propList = {}
local playersList = {}
local fireList = {}
local smokeList = {}
DebugPrint("Attempting to build callout: "..calloutData.CalloutName)
calloutBuilt = Config.Callouts[calloutData.calloutId].server(request, src, calloutData, pedList, vehicleList, objectList, propList, playersList, fireList, smokeList)
-- Check if callout was built
if calloutBuilt then
ERS_InsertEntitiesIntoCalloutList(src, pedList, vehicleList, objectList, fireList, smokeList)
QueueUpdateRequest(function(success)
if success then
DebugPrint("[processBuildCalloutQueue] Update completed successfully.")
-- Update callout UI for the owner & attached players of the callout
DebugPrint("[processBuildCalloutQueue] Updating callout user interface for hostId "..src)
TriggerClientEvent(Config.EventPrefix..':updateCalloutUserInterface', src, src)
for index, callout in ipairs(ActiveCalloutsList) do
if callout.hostId == src then
for i, userServerId in pairs(callout.playersList) do
DebugPrint("[processBuildCalloutQueue] Updating callout user interface for attached playerId "..userServerId)
TriggerClientEvent(Config.EventPrefix..':updateCalloutUserInterface', userServerId, src)
end
break
end
end
TriggerClientEvent(Config.EventPrefix..':startCallout', src, pedList, vehicleList, playersList, objectList, propList, fireList, smokeList, calloutData)
DebugPrint("Successfully built callout: "..calloutData.CalloutName)
else
DebugPrint("[processBuildCalloutQueue] Update failed or was skipped.")
end
end)
else
local message = Config.Messages[Config.Language].ServerCouldNotBuildCalloutError
TriggerClientEvent(Config.EventPrefix..':notificationMessage', src, message)
-- Inform the client to re-enable cancel and detach since build failed
TriggerClientEvent(Config.EventPrefix..':buildCalloutFailed', src)
print("^1ERROR^7 It is possible you forgot to return true at the end of your callout server function OR:")
print("^1ERROR^7 None of the enabled callouts could be built, please make sure you have at least 1 callout enabled.")
end
Citizen.SetTimeout(1000, function()
processingBuildCalloutQueue = false
processBuildCalloutQueue()
end)
end
--================ Open source functions =================--
--