Skip to content

Commit 7955351

Browse files
authored
Merge pull request #357 from srslyyyy/gamemodestopper-fix
editor_main: improve gamemodestopper
2 parents 7c135ae + 3063712 commit 7955351

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function isResourceRunning(res)
2-
return getResourceState(res)=="running"
2+
return getResourceState(res) == "running"
33
end
44

55
function isGamemode(res)
@@ -10,17 +10,25 @@ function isMap(res)
1010
return exports.mapmanager:isMap(res)
1111
end
1212

13-
addEventHandler("onResourceStart", getResourceRootElement(),
14-
function()
15-
for index,resource in ipairs(getResources()) do
16-
if isResourceRunning(resource) and (isGamemode(resource) or isMap(resource)) then
17-
if hasObjectPermissionTo(getThisResource(), "function.stopResource") then
18-
stopResource(resource)
19-
else
20-
outputDebugString("Editor: Unable to stop running gamemodes (no access to function.stopResource)")
21-
return
22-
end
13+
function onResourceStart(startedResource)
14+
if not hasObjectPermissionTo(startedResource, "function.stopResource") then
15+
outputDebugString("Editor: Unable to stop running gamemodes (no access to function.stopResource)")
16+
17+
return false
18+
end
19+
20+
local resourcesTable = getResources()
21+
22+
for resourceID = 1, #resourcesTable do
23+
local resourceElement = resourcesTable[resourceID]
24+
25+
if isResourceRunning(resourceElement) then
26+
local gamemodeOrMap = isGamemode(resourceElement) or isMap(resourceElement)
27+
28+
if gamemodeOrMap then
29+
stopResource(resourceElement)
2330
end
2431
end
2532
end
26-
)
33+
end
34+
addEventHandler("onResourceStart", resourceRoot, onResourceStart)

0 commit comments

Comments
 (0)