jaypar

Reactor Power

Feb 23rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Created and Developed by jaypar(Lapito1297)
  2.  
  3. for k,v in pairs(rs.getSides()) do
  4.  if (peripheral.getType(v) == "openperipheral_bridge") then
  5.   glass = peripheral.wrap(v)
  6.   break
  7.  end
  8. end
  9. function current()
  10.  if fs.exists("startup") == true then
  11.   c = fs.open("startup", "r")
  12.   ch = c.readAll()
  13.   checked = ch
  14.   return checked
  15.  end
  16. end
  17. function update()
  18.  shell.run("pastebin get bE1Kt29y update")
  19.  term.clear()
  20.  term.setCursorPos(1,1)
  21.  u = fs.open("update", "r")
  22.  ud = u.readAll()
  23.  cur = ud
  24.  return cur
  25. end
  26. function resp()
  27.  print("Do you wish to update?(please type yes or no)")
  28.  res = io.read()
  29.  term.clear()
  30.  return res
  31. end
  32. function upd()
  33. if firstTime() == false then
  34.  while true do
  35.   if (update() ~= current()) and (resp() == "yes") then
  36.    p = fs.open("startup", "w")
  37.    p.write(ud)
  38.    p.flush()
  39.    shell.run("pastebin get A9NYRnka changelog")
  40.    ch = fs.open("changelog", "r")
  41.    cha = ch.readAll()
  42.    print(cha)
  43.    print("Restart will begin in 25 seconds")
  44.    sleep(20)
  45.    term.clear()
  46.    term.setCursorPos(1,1)
  47.    term.write("Restarting in 5 seconds for update")
  48.    sleep(1)
  49.    term.clear()
  50.    term.setCursorPos(1,1)
  51.    term.write("Restarting in 4 seconds for update")
  52.    sleep(1)
  53.    term.clear()
  54.    term.setCursorPos(1,1)
  55.    term.write("Restarting in 3 seconds for update")
  56.    sleep(1)
  57.    term.clear()
  58.    term.setCursorPos(1,1)
  59.    term.write("Restarting in 2 seconds for update")
  60.    sleep(1)
  61.    term.clear()
  62.    term.setCursorPos(1,1)
  63.    term.write("Restarting in 1 seconds for update")
  64.    sleep(1)
  65.    term.clear()
  66.    term.setCursorPos(1,1)
  67.    term.write("Restarting")
  68.    sleep(0.5)
  69.    shell.run("reboot")
  70.   end
  71.  if fs.exists("changelog") then
  72.   fs.delete("changelog")
  73.  end
  74.  fs.delete("update")
  75.  sleep(0.5)
  76.  end
  77. end
  78. end
  79. function firstTime()
  80.  if fs.exists("reactorOptions") == false then
  81.   return false
  82.  else
  83.   return true
  84.  end
  85. end
  86. function onoff(bool)
  87.  react.setActive(bool)
  88. end
  89. function reactor()
  90.  Options = {}
  91.  o = fs.open("reactorOptions", "r")
  92.  p = o.readAll()
  93.  Options = textutils.unserialize(p)
  94.  powerMax = Options.powerMax
  95.  powerMin = Options.powerMin
  96.  side = Options.side
  97.  react = peripheral.wrap(side)
  98.  while true do
  99.   power = react.getEnergyStored()
  100.   if power >= powerMax then
  101.    onoff(false)
  102.   end
  103.   if power <= powerMin then
  104.    onoff(true)
  105.   end
  106.   sleep(0.1)
  107.  end
  108. end
  109. function main()
  110. if firstTime() == false then
  111.  Options = {}
  112.  Options = fs.open("reactorOptions", "w")
  113.  term.clear()
  114.  term.setCursorPos(11,1)
  115.  term.write("What side is the Reactor on?")
  116.  term.setCursorPos(11,2)
  117.  term.write("(Examples: back, top, left,")
  118.  term.setCursorPos(16,3)
  119.  term.write("right, bottom)")
  120.  term.setCursorPos(22,4)
  121.  side = io.read()
  122.  term.clear()
  123.  term.setCursorPos(11,1)
  124.  term.write("When do you want the reactor")
  125.  term.setCursorPos(11,2)
  126.  term.write("to turn off?(example: 9000000)")
  127.  term.setCursorPos(22,3)
  128.  powerMax = io.read()
  129.  powerMax2 = textutils.unserialize(powerMax)
  130.  term.clear()
  131.  term.setCursorPos(11,1)
  132.  term.write("When do you want the reactor")
  133.  term.setCursorPos(11,2)
  134.  term.write("to turn on?(Example: 1000)")
  135.  term.setCursorPos(22,3)
  136.  powerMin = io.read()
  137.  powerMin2 = textutils.unserialize(powerMin)
  138.  tab = {
  139.  side = side,
  140.  powerMax = powerMax2,
  141.  powerMin = powerMin2
  142.  }
  143.  Options.write(textutils.serialize(tab))
  144.  Options.flush()
  145.  reactor()
  146. else
  147.  reactor()
  148. end
  149. end
  150. parallel.waitForAll(main, upd)
Add Comment
Please, Sign In to add comment