Advertisement
Guest User

reactor_autostart

a guest
Apr 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. os.loadAPI("disk/attached_devices")
  2. os.loadAPI("disk/var_dump")
  3.  
  4. function react(t)
  5.   local devices = attached_devices.load_attached_devices()
  6.   --var_dump.var_dump(devices.drives[2])
  7.  
  8.   local reactor = devices.drives[2].obj
  9.  
  10.   local running = reactor.getActive()
  11.   local energy  = reactor.getEnergyStored()
  12.   local fuel = reactor.getFuelAmount()
  13.   local last_tick = reactor.getEnergyProducedLastTick()
  14.  
  15.   local task = ""
  16.  
  17.   if fuel == 0 then
  18.     reactor.setActive(false)
  19.     task = "STOPPED. NO FUEL"
  20.   elseif energy < 8000000 and running ==  false then
  21.     task = "STARTING..."
  22.     reactor.setActive(true)
  23.     if reactor.getActive()==false then
  24.       task = task.." FAILED TO START"
  25.     else
  26.       task = task.." (SUCCESS)"
  27.     end
  28.   elseif running == false then
  29.     task = "NOT RUNNING"
  30.   elseif running == true and energy > 8000000 then
  31.     task = "STOPPING..."
  32.     reactor.setActive(false)
  33.     if reactor.getActive()==true then
  34.       task = task.." FAILED TO STOP"
  35.     else
  36.       task = task.." (SUCCESS)"
  37.     end
  38.   elseif running == true then
  39.     task = "RUNNING"
  40.   end
  41.  
  42.  
  43.   local output = "** [Reactor Daemon] "..task..", Energy Stored: "..energy
  44.   if task == "RUNNING" then
  45.     output = output..", Energy Produced Last Tick: "..last_tick
  46.   end
  47.   output = output.. ", Fuel Remaining: "..fuel
  48.  
  49.   print(output)
  50.  
  51.   os.loadAPI("disk/discord")
  52.   if not (task == t) then
  53.     discord.webhook(output)
  54.   end
  55.  
  56.   return task
  57. end
  58.  
  59.  
  60. local s = ""
  61.  
  62. while true do
  63.   s = react(s)
  64.   os.sleep(15)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement