IsResourceRunning: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 3: Line 3:


==Syntax==  
==Syntax==  
You can insert this code example in your resources.
*'''isResourceRunning''' You can insert this code example in your resources.


===Required Arguments===  
===Required Arguments===  
*'''isResourceRunning:''' The value to check resources
*'''isResourceRunning:''' The value to check resources


==Example==
==Example check isResourceRunning(resName)==
<section name="Example1" class="shared" show="true">
<section name="isResourceRunning" class="shared" show="true">
You can insert this code example in your resources.
You can insert this code example in your resources.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function isResourceRunning(resName)
function isResourceRunning(resName)
local res = getResourceFromName(resName)
  local res = getResourceFromName(resName)
return (res) and (getResourceState(res) == "running")
  return (res) and (getResourceState(res) == "running")
end
end


Line 24: Line 24:
   --alert
   --alert
end
end
]]


addCommandHandler('pos', function (commandName)
addCommandHandler('pos', function (commandName)
Line 34: Line 33:
     end
     end
end )
end )
]]


</syntaxhighlight>
</syntaxhighlight>
Line 40: Line 40:
==See Also==
==See Also==
{{Resource_functions}}
{{Resource_functions}}
[[ru:isBan]]

Latest revision as of 03:41, 2 April 2026

Syntax

  • isResourceRunning You can insert this code example in your resources.

Required Arguments

  • isResourceRunning: The value to check resources

Example check isResourceRunning(resName)

Click to collapse [-]
isResourceRunning

You can insert this code example in your resources.

function isResourceRunning(resName)
   local res = getResourceFromName(resName)
   return (res) and (getResourceState(res) == "running")
end

-- Example of inserting into system code:
--[[
if isResourceRunning("admin") then
   --code
else
   --alert
end

addCommandHandler('pos', function (commandName)
    if isResourceRunning("admin") then
       local x,y,z = getElementPosition(localPlayer)
       outputChatBox( x ..', '.. y ..', '.. z, 255, 255, 255 )
    else
       outputChatBox("The resource is not running 'admin'.", 255, 0, 0)
    end
end )
]]

See Also