Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions [editor]/editor_main/gamemodestopper.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function isResourceRunning(res)
return getResourceState(res)=="running"
return getResourceState(res) == "running"
end

function isGamemode(res)
Expand All @@ -10,17 +10,25 @@ function isMap(res)
return exports.mapmanager:isMap(res)
end

addEventHandler("onResourceStart", getResourceRootElement(),
function()
for index,resource in ipairs(getResources()) do
if isResourceRunning(resource) and (isGamemode(resource) or isMap(resource)) then
if hasObjectPermissionTo(getThisResource(), "function.stopResource") then
stopResource(resource)
else
outputDebugString("Editor: Unable to stop running gamemodes (no access to function.stopResource)")
return
end
function onResourceStart(startedResource)
if not hasObjectPermissionTo(startedResource, "function.stopResource") then
outputDebugString("Editor: Unable to stop running gamemodes (no access to function.stopResource)")

return false
end

local resourcesTable = getResources()

for resourceID = 1, #resourcesTable do
local resourceElement = resourcesTable[resourceID]

if isResourceRunning(resourceElement) then
local gamemodeOrMap = isGamemode(resourceElement) or isMap(resourceElement)

if gamemodeOrMap then
stopResource(resourceElement)
end
end
end
)
end
addEventHandler("onResourceStart", resourceRoot, onResourceStart)