Jump to content

Need to know function


Recommended Posts

Try this one

function YourFunction() 
    for index, res in ipairs(getResources()) do 
        local state = getResourceState(res) 
        if state == "running" then  
        -- You code here 
        end 
    end  
end  

Link to comment
Try this one
function YourFunction() 
    for index, res in ipairs(getResources()) do 
        local state = getResourceState(res) 
        if state == "running" then  
        -- You code here 
        end 
    end  
end  

I'll try it, but could you explain me this

    for index, res in ipairs(getResources()) do 

Just gimme a link leads me to wiki, to read about "for...do", if possible.

Link to comment

I know them both already..... As i said, i need to check for starting resources in general, not a speciefied resource... Do you understand? Lemme make an example

if a resource is starting then 
  

Not a specefied resource... because , i need to do an action, when every resource starts....

Thats why he showed you the event, they trigger when a resource is about to start / starting.

I've put the code for both a server script and a client script, the only difference is the name of the event ("onResourceStart" and "onClientResourceStart")

This is how it's done:

-- SERVER variation 
function checkStartedRes(res) 
    -- Code here 
    outputChatBox("Started resource: " .. getResourceName(res)) 
end 
addEventHandler("onResourceStart",root,checkStartedRes) 
  
  
  
  
  
  
-- CLIENT variation 
  
function checkStartedRes(res) 
    -- Code here 
    outputChatBox("Started resource: " .. getResourceName(res)) 
end 
addEventHandler("onClientResourceStart",root,checkStartedRes) 

Use onResourcePreStart if you want it to trigger before a resource is starting.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...