Difference between revisions of "StopResource"

From Multi Theft Auto: Wiki
Jump to: navigation, search
(add oop syntax)
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
{{Server function}}
 
{{Server function}}
 
This function stops a running resource.<br>
 
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 called. This happens after the scripts are done executing for this server frame.
+
'''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 8: Line 8:
 
bool stopResource ( resource theResource )
 
bool stopResource ( resource theResource )
 
</syntaxhighlight>  
 
</syntaxhighlight>  
 
+
{{OOP||[[resource]]:stop}}
 
===Required Arguments===  
 
===Required Arguments===  
 
*'''theResource:''' the [[resource]] that should be stopped.
 
*'''theResource:''' the [[resource]] that should be stopped.

Revision as of 16:26, 1 January 2015

This function stops a running resource.
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

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