EngMohamedLish Posted June 8, 2015 Share Posted June 8, 2015 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. Link to comment
novo Posted June 8, 2015 Share Posted June 8, 2015 You may use onResourcePreStart or onResourceStart. Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 You may use onResourcePreStart or onResourceStart. 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.... Link to comment
Walid Posted June 8, 2015 Share Posted June 8, 2015 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
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 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
Drakath Posted June 8, 2015 Share Posted June 8, 2015 http://www.lua.org/pil/4.3.4.html http://www.lua.org/manual/5.1/manual.html#pdf-ipairs Link to comment
AfuSensi Posted June 8, 2015 Share Posted June 8, 2015 You may use onResourcePreStart or onResourceStart. 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now