mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
31 lines
832 B
Lua
31 lines
832 B
Lua
local startedResources = {}
|
|
|
|
local function stateChanged(resourceName, state)
|
|
local callbacks = startedResources[resourceName]
|
|
if not callbacks then return end
|
|
for i=1, #callbacks do
|
|
local cb = callbacks[i]
|
|
cb(state)
|
|
end
|
|
end
|
|
|
|
AddEventHandler("onResourceStart", function(resourceName)
|
|
stateChanged(resourceName, true)
|
|
end)
|
|
|
|
AddEventHandler("onResourceStop", function(resourceName)
|
|
stateChanged(resourceName, false)
|
|
end)
|
|
|
|
function NDCore.isResourceStarted(resourceName, cb)
|
|
local started = GetResourceState(resourceName) == "started"
|
|
if cb then
|
|
if not startedResources[resourceName] then
|
|
startedResources[resourceName] = {}
|
|
end
|
|
startedResources[resourceName][#startedResources[resourceName]+1] = cb
|
|
cb(started)
|
|
end
|
|
return started
|
|
end
|