2023-07-11 01:06:00 +02:00
|
|
|
local startedResources = {}
|
2023-10-25 21:47:43 +02:00
|
|
|
|
|
|
|
|
local function stateChanged(resourceName, state)
|
|
|
|
|
local callbacks = startedResources[resourceName]
|
|
|
|
|
if not callbacks then return end
|
|
|
|
|
for _, cb do
|
|
|
|
|
cb(state)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-07-11 01:06:00 +02:00
|
|
|
|
|
|
|
|
AddEventHandler("onResourceStart", function(resourceName)
|
2023-10-25 21:47:43 +02:00
|
|
|
stateChanged(resourceName, true)
|
2023-07-11 01:06:00 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
AddEventHandler("onResourceStop", function(resourceName)
|
2023-10-25 21:47:43 +02:00
|
|
|
stateChanged(resourceName, false)
|
2023-07-11 01:06:00 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
function NDCore.isResourceStarted(resourceName, cb)
|
|
|
|
|
local started = GetResourceState(resourceName) == "started"
|
|
|
|
|
if cb then
|
2023-10-25 21:47:43 +02:00
|
|
|
if not startedResources[resourceName] then
|
|
|
|
|
startedResources[resourceName] = {}
|
|
|
|
|
end
|
|
|
|
|
local invokingResource = GetInvokingResource()
|
|
|
|
|
startedResources[resourceName][invokingResource] = cb
|
2023-07-11 01:06:00 +02:00
|
|
|
cb(started)
|
|
|
|
|
end
|
|
|
|
|
return started
|
|
|
|
|
end
|