Jump to content

Restart resource automatically


Yussuf

Recommended Posts

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

Well, as you're new to Lua scripting I won't be rude :P, 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 by Guest
Link to comment

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

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

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