Jump to content

Need to know function


Recommended Posts

Posted

I need to know, how to check if there are starting resources, If you didn't get it. I mean something like, checks if a resource is starting, i can do an event. I don't mean a specefied resource, I talk about, if "any" resource is starting.

Posted

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  

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
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.

Posted

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.

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...