Yussuf Posted December 13, 2011 Share Posted December 13, 2011 hello ! i'm beginner in Lua language and i would create resource wich restart some other resource every time (timer wich repeat for unlimited ) but no thing happens : function restartresource () local res = getResourceName ("ressource.xml") if getResourceName then restart (res) end end setTimer ( restartresource , 10000 , .. ) resource.xml : <resource> <resource src="ressource.name"> </resource> Please can you help me ? Thanks Link to comment
Castillo Posted December 13, 2011 Share Posted December 13, 2011 (edited) Well, as you're new to Lua scripting I won't be rude , but this is a mess . What I understand is that you're trying to restart resources from a XML file. -- resources.xml "myResourceName"> function restartResources () local resourcesFile = xmlLoadFile("resources.xml") if (not resourcesFile) then outputDebugString("Failed to load 'resources.xml'.",2) return end for index, child in ipairs(xmlNodeGetChildren(resourcesFile)) do local resName = xmlNodeGetAttribute(child, "name") local resource = getResourceFromName(resName) if (resource and getResourceState(resource) == "running") then restartResource(resource) end end xmlUnloadFile(resourcesFile) end setTimer ( restartResources, 10000, 0 ) Edited December 13, 2011 by Guest Link to comment
Yussuf Posted December 13, 2011 Author Share Posted December 13, 2011 Thanks but always it show me Fail to load resource.xml !!!?? Link to comment
Castillo Posted December 13, 2011 Share Posted December 13, 2011 Do you have the file "resources.xml"? Link to comment
Yussuf Posted December 13, 2011 Author Share Posted December 13, 2011 yes !! Maybe i did a mistake ^^ : (for example) <resources> <resource name="freeroam"> </resources> Is it true ?? Link to comment
Castillo Posted December 13, 2011 Share Posted December 13, 2011 Are you completely sure that the file is called "resources.xml" and not "resource.xml"? Link to comment
Yussuf Posted December 13, 2011 Author Share Posted December 13, 2011 Yes i'm sure ... Link to comment
Castillo Posted December 13, 2011 Share Posted December 13, 2011 The same things happens to me... I don't know I have the file too. Edit: I found the problem, the XML wasn't correct: "resourceName"/> P.S: Copy my SCRIPT again, I fixed a error. Link to comment
Yussuf Posted December 13, 2011 Author Share Posted December 13, 2011 No the same thing ! First it showed me : Access denied @ ... so i added a line in admin group in the acl.xml file Then it showed me Failed to load resource.xml I think that there's an error in resource.xml (note : when i should write the resource name : 1 or 2 ?? i tried the both but no result ) Link to comment
Evil-Cod3r Posted December 13, 2011 Share Posted December 13, 2011 try this function this ( theResource ) local they = getResourceFromName ( "freeroam" ) if ( they and theResource == they ) then if getResourceState(freeroam) == "running" then restartResource(freeroam) end addEventHandler ( "onResourceStart", getRootElement(), this ) Link to comment
Yussuf Posted December 13, 2011 Author Share Posted December 13, 2011 Thanks Solidsnake14 for your help Thank you so much Evil-Cod3r I modified your resource like this (without checking if it's running or not ) function this ( theResource ) local they = getResourceFromName ( "freeroam" ) if getResourceFromName then restartResource(they) end end setTimer (this, 10000,0 ) Simple ^^ Link to comment
50p Posted December 13, 2011 Share Posted December 13, 2011 Thanks Solidsnake14 Thank you so much Evil-Cod3r I modified your resource like this (without checking if it's running or not ) function this ( theResource ) local they = getResourceFromName ( "freeroam" ) if getResourceFromName then restartResource(they) end end setTimer (this, 10000,0 ) Simple ^^ Your resource is hard-coded now. This means if you want to add another resource that you want to restart after certain amount of time, you have to modify the code. Make it so you load xml file, like before. Make sure the .xml file is added to meta.xml as and try to use getResourceConfig instead. You can still use xml functions with returned value that is xmlnode. I've always preferred to use this instead of xmlLoadFile. You have to remember to use xmlUnloadFile when you're finished with reading the file. Link to comment
Castillo Posted December 13, 2011 Share Posted December 13, 2011 My script works perfectly, you must add the resource which has the script to restart them to the ACL. 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