Skip to content

Commit bfad624

Browse files
committed
Update gamemodestopper.lua
1 parent 7816898 commit bfad624

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed
Lines changed: 23 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,28 @@ 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+
local stopPermission = hasObjectPermissionTo(startedResource, "function.stopResource")
15+
16+
if not stopPermission then
17+
outputDebugString("Editor: Unable to stop running gamemodes (no access to function.stopResource)")
18+
19+
return false
20+
end
21+
22+
local resourcesTable = getResources()
23+
24+
for resourceID = 1, #resourcesTable do
25+
local resourceElement = resourcesTable[resourceID]
26+
local resourceRunning = isResourceRunning(resourceElement)
27+
28+
if resourceRunning then
29+
local gamemodeOrMap = isGamemode(resourceElement) or isMap(resourceElement)
30+
31+
if gamemodeOrMap then
32+
stopResource(resourceElement)
2333
end
2434
end
2535
end
26-
)
36+
end
37+
addEventHandler("onResourceStart", resourceRoot, onResourceStart)

0 commit comments

Comments
 (0)