StopResource: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(corrected example, cleaned up slightly.)
Line 9: Line 9:


===Required Arguments===  
===Required Arguments===  
*'''theResource:''' the [[resource]] we want to stop.
*'''theResource:''' the [[resource]] that should be stopped.


===Returns===
===Returns===
Line 15: Line 15:


==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()
Line 21: Line 21:
     local allResources = getResources()
     local allResources = getResources()
     -- for each one of them,
     -- for each one of them,
     for i, res in ipairs(allResources) do
     for i, resource in ipairs(allResources) do
         -- if it's running,
         -- if it's running, and it is not the current resource
         if getResourceState(resource) == "running" then
         if ( getResourceState(resource) == "running" ) and ( resource ~= getThisResource() ) then
             -- then stop it
             -- then stop it
             stopResource(res)
             stopResource(resource)
         end
         end
     end
     end

Revision as of 15:44, 29 August 2007

This function stops a running resource.

Syntax

bool stopResource ( resource theResource )

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