StopResource: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (→See Also) |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This function stops a running resource. | {{Server function}} | ||
This function stops a running resource.<br> | |||
{{Note| This function does not stop the resource immediately, so don't expect that it starts stopping until the [[onResourceStop]] event for that resource is triggered. This happens after the scripts are done executing for this server frame.}} | |||
==Syntax== | ==Syntax== | ||
Line 6: | Line 8: | ||
bool stopResource ( resource theResource ) | bool stopResource ( resource theResource ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[resource]]:stop}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theResource:''' the [[resource]] | *'''theResource:''' the [[resource]] that should be stopped. | ||
===Returns=== | ===Returns=== | ||
Line 14: | Line 16: | ||
==Example== | ==Example== | ||
This function stops all running resources. | This function stops all running resources except the current one. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function stopAllResources() | function stopAllResources() | ||
-- we store a table of resources | |||
local allResources = getResources() | |||
-- for each one of them, | |||
for i, resource in ipairs(allResources) do | |||
-- if it's running, and it is not the current resource | |||
if ( getResourceState(resource) == "running" ) and ( resource ~= getThisResource() ) then | |||
-- then stop it | |||
stopResource(resource) | |||
end | |||
end | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Resource_functions}} | {{Resource_functions|server}} |
Latest revision as of 22:49, 6 September 2024
This function stops a running resource.
Syntax
bool stopResource ( resource theResource )
OOP Syntax Help! I don't understand this!
- Method: resource:stop(...)
Required Arguments
- theResource: the resource that should be stopped.
Returns
Returns true if the resource was stopped, false if the stopping failed, or an invalid resource was passed.
Example
This function stops all running resources except the current one.
function stopAllResources() -- we store a table of resources local allResources = getResources() -- for each one of them, for i, resource in ipairs(allResources) do -- if it's running, and it is not the current resource if ( getResourceState(resource) == "running" ) and ( resource ~= getThisResource() ) then -- then stop it stopResource(resource) end end end
See Also
- addResourceConfig
- addResourceMap
- callRemote
- copyResource
- createResource
- deleteResource
- getResourceACLRequests
- getResourceInfo
- getResourceLastStartTime
- getResourceLoadFailureReason
- getResourceLoadTime
- getResourceMapRootElement
- getResourceOrganizationalPath
- getResources
- isResourceArchived
- isResourceProtected
- refreshResources
- removeResourceFile
- renameResource
- restartResource
- setResourceInfo
- startResource
- stopResource
- updateResourceACLRequest
- Shared
- abortRemoteRequest
- call
- fetchRemote
- getResourceConfig
- getResourceDynamicElementRoot
- getResourceExportedFunctions
- getResourceFromName
- getResourceName
- getResourceRootElement
- getResourceState
- getThisResource
- getRemoteRequests
- getRemoteRequestInfo