Jump to content

resource autorestart?


Recommended Posts

setTimer ( 
      function ( ) 
           for k, v in ipairs ( getResources ( ) ) do -- get all resources 
                 restartResource ( v ) -- restart all resources 
           end -- end the for-loop 
      end, 
3600000, 0 ) -- time and times to run 
  

3600000 = 1 hour

Code updated.

Edited by Guest
Link to comment

you need to add admin rights to the resource

ResourceName={} --here put your resource names like ResourceName={"resource1","reasource2"} 
local tim=60000 -- time when to restart (1min) 
local amount= 1   -- how many time to restart ( 0 for infinit ) 
function restart() 
for i,v in pairs">pairs(ResourceName) do  
restartResource( getResourceFromName(v)) 
outputChatBox("Resource: "..v.." was restarted" 
end 
 end 
setTimer(restart,tim,amount) 
  
  

LUA bug :D

ResourceName={} --here put your resource names like ResourceName={"resource1","reasource2"} 
local tim=60000 -- time when to restart (1min) 
local amount= 1   -- how many time to restart ( 0 for infinit ) 
function restart() 
for i,v in pairs(ResourceName) do  
restartResource( getResourceFromName(v)) 
outputChatBox("Resource: "..v.." was restarted" 
end 
 end 
setTimer(restart,tim,amount) 

Link to comment

local resources =  
{ 
      'myResource', 
      'myResource2' 
} 
  
local time = 60000 
local timesToRun = 0 
  
setTimer ( 
      function ( ) 
           for k, v in pairs ( resources ) do 
               restartResource ( getResourceFromName ( v ) ) 
           end 
      end, 
time,timesToRun)     
  

Please tabulate your code properly.

And as you said, you need to put your resource in ACL Group "Admin" if you want to script restart resources else you will get error Acess Denied.

Edited by Guest
Link to comment
local resourcesToRestart = { "test_resource", "test_resource2" } -- Resource names to restart. 
local timeInterval = 60000 -- The number of milliseconds that should elapse before the function is called. (the minimum is 50) (1000 milliseconds = 1 second) 
local timesToExecute = 1   -- The number of times you want the timer to execute, or 0 for infinite repetitions 
  
function restartResources() 
    for index, resourceName in ipairs ( resourcesToRestart ) do 
        if getResourceFromName ( resourceName ) then 
            restartResource( getResourceFromName ( resourceName ) ) 
            outputDebugString ( "Resource: ".. resourceName .." was restarted") 
        end 
    end 
end 
setTimer( restartResources, timeInterval, timesToExecute ) 

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