Advertisement
JimmyWO

[ComputerCraft] [LUA] Reactor Control v2.2

Jun 29th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.26 KB | None | 0 0
  1. --------------------------------------------------
  2. ------------------For Minecraft-------------------
  3. ---For 2 IC2 reactor on each side of a computer---
  4. ------------For advanced computers only-----------
  5. --------------------------------------------------
  6.  
  7. softwareVersion = "2.2"
  8. y = 1
  9. rednet.open("back")
  10. --------------------------------------------------
  11. function time()
  12.   local time = os.time()
  13.   ttc(colors.gray)
  14.   timeF = textutils.formatTime(time,true)
  15.  
  16.   if time < 10 then
  17.     term.setCursorPos(1,y)
  18.     write("[0"..timeF.."]")
  19.     T = "[0"..timeF.."]"
  20.   else
  21.     term.setCursorPos(1,y)
  22.     write("["..timeF.."]")
  23.     T = "["..timeF.."]"
  24.   end
  25.  
  26. end  
  27. --------------------------------------------------
  28. function ver()
  29.   term.setCursorPos(1,1)
  30.   ttc(colors.yellow)
  31.   write("ReactorControl V"..softwareVersion)
  32. end
  33. --------------------------------------------------
  34. function line()
  35.   ver()
  36.  
  37.   if y <=13 then
  38.     y=y+1
  39.   else
  40.     term.scroll(1)
  41.   end
  42.  
  43.   term.setCursorPos(8,y)
  44. end
  45. --------------------------------------------------
  46. function ttc(x)
  47.   term.setTextColor(x)
  48. end
  49. --------------------------------------------------
  50. function prompt()
  51.   ttc(colors.white)
  52.   write(":")
  53.   ttc(colors.green)
  54.   write("Admin ")
  55.   ttc(colors.yellow)
  56.   write("$> ")
  57.   ttc(colors.white)
  58.   command = read()
  59. end
  60. --------------------------------------------------
  61. function helpCommand()
  62.   ttc(colors.yellow)
  63.   write(" --------------")
  64.   line()
  65.   ttc(colors.lightBlue)
  66.   write(" help ")
  67.   ttc(colors.white)
  68.   write("= ")
  69.   ttc(colors.lime)
  70.   write("List all commands")
  71.   line()
  72.   ttc(colors.lightBlue)
  73.   write(" core ")
  74.   ttc(colors.white)
  75.   write("[")
  76.   ttc(colors.lightGray)
  77.   write("side")
  78.   ttc(colors.white)
  79.   write("] ")
  80.   write("[")
  81.   ttc(colors.lightGray)
  82.   write("on")
  83.   ttc(colors.white)
  84.   write("/")
  85.   ttc(colors.lightGray)
  86.   write("off")
  87.   ttc(colors.white)
  88.   write("] ")
  89.   ttc(colors.white)
  90.   write("= ")
  91.   ttc(colors.lime)
  92.   write("Core on")
  93.   ttc(colors.white)
  94.   write("/")
  95.   ttc(colors.lime)
  96.   write("off")
  97.   line()
  98.   ttc(colors.lightBlue)
  99.   write(" energy amount ")
  100.   ttc(colors.white)
  101.   write("= ")
  102.   ttc(colors.lime)
  103.   write("Check energy amount")
  104.   line()
  105.   ttc(colors.lightBlue)
  106.   write(" clear ")
  107.   ttc(colors.white)
  108.   write("= ")
  109.   ttc(colors.lime)
  110.   write("Clear the terminal")
  111.   line()
  112.   ttc(colors.lightBlue)
  113.   write(" stop ")
  114.   ttc(colors.white)
  115.   write("= ")
  116.   ttc(colors.lime)
  117.   write("Stop the reactor")
  118.   line()
  119.   ttc(colors.lightBlue)
  120.   write(" run ")
  121.   ttc(colors.white)
  122.   write("= ")
  123.   ttc(colors.lime)
  124.   write("Run the reactor")
  125.   line()
  126.   ttc(colors.yellow)
  127.   write(" --------------")
  128.   line()
  129. end
  130. --------------------------------------------------
  131. function core(side,status,col)
  132.   ttc(colors.lightGray)
  133.   write(" Waiting")
  134.   sleep(0.5)
  135.   write(".")
  136.   sleep(0.5)
  137.   write(".")
  138.   sleep(0.5)
  139.   write(".")
  140.   line()
  141.   ttc(colors.yellow)
  142.   write(" >>> ")
  143.   ttc(colors.lightBlue)
  144.   write("Core ")
  145.   ttc(colors.lime)
  146.   write(side)
  147.   ttc(colors.lightBlue)
  148.   write(" is ")
  149.   ttc(col)
  150.   write(status)
  151.   line()
  152.  
  153.   if side == "Left" and status == "ON" then
  154.     rs.setOutput("left",true)
  155.   elseif side == "Left" and status == "OFF" then
  156.     rs.setOutput("left",false)
  157.   elseif side == "Right" and status == "ON" then
  158.     rs.setOutput("right",true)
  159.   elseif side == "Right" and status == "OFF" then
  160.     rs.setOutput("right",false)
  161.   end
  162.  
  163. end
  164. --------------------------------------------------
  165. function termClear()
  166.   term.clear()
  167.   y=1
  168.   line()
  169. end
  170. --------------------------------------------------
  171. function stop()
  172.   ttc(colors.lightGray)
  173.   write(" Stopping")
  174.   sleep(0.5)
  175.   write(".")
  176.   sleep(0.5)
  177.   write(".")
  178.   sleep(0.5)
  179.   write(".")
  180.   line()
  181.   ttc(colors.yellow)
  182.   write(" >>> ")
  183.   ttc(colors.lightBlue)
  184.   write("Reactor ")
  185.   ttc(colors.red)
  186.   write("STOPPED")
  187.   rs.setOutput("left",false)
  188.   rs.setOutput("right",false)
  189.   line()
  190. end
  191. --------------------------------------------------
  192. function run()
  193.   ttc(colors.lightGray)
  194.   write(" Running")
  195.   sleep(0.5)
  196.   write(".")
  197.   sleep(0.5)
  198.   write(".")
  199.   sleep(0.5)
  200.   write(".")
  201.   sleep(0.5)
  202.   line()
  203.   ttc(colors.yellow)
  204.   write(" >>> ")
  205.   ttc(colors.lightBlue)
  206.   write("Reactor is ")
  207.   ttc(colors.green)
  208.   write("RUNNING")
  209.   line()
  210.   rs.setOutput("left",true)
  211.   rs.setOutput("right",true)
  212.   end
  213. --------------------------------------------------
  214. function logsW()
  215.   h = fs.open("logLine","r")
  216.   l = h.readLine(1)
  217.   h.close()
  218.   logFile = fs.open("logs","a")
  219.   logFile.writeLine(T.." : "..command,l)
  220.   logFile.close()
  221.   l = l+1
  222.   h = fs.open("logLine","w")
  223.   h.write(l)
  224.   h.close()  
  225. end
  226. --------------------------------------------------
  227. function energyAmount()
  228.   ttc(colors.lightGray)
  229.   write(" Checking...")
  230.   line()
  231.   id, data = rednet.receive(1)
  232.   e = string.reverse(data)
  233.  
  234.   if data < 1000 then
  235.     C = data
  236.   elseif data >= 1000 and data <1000000 then
  237.     a = string.sub(e, 1,3)
  238.     A = a.." "
  239.     b = string.sub(e, 4,6)
  240.     C = A..b
  241.     eF = string.reverse(C)
  242.    elseif data >= 1000000 then
  243.     a = string.sub(e, 1,3)
  244.     A = a.." "
  245.     b = string.sub(e, 4,6)
  246.     B = b.." "
  247.     c = string.sub(e,7,9)
  248.     C = A..B..c
  249.     eF = string.reverse(C)
  250.   end
  251.  
  252.   ttc(colors.yellow)
  253.   write(" >>> ")
  254.   ttc(colors.lime)
  255.   write(eF.." ")
  256.   ttc(colors.lightBlue)
  257.   write("EU")
  258.   line()
  259.  
  260. end
  261. --------------------------------------------------
  262. term.clear()
  263. line()
  264.  
  265. --Main loop
  266.  
  267. while true do
  268.  
  269.   prompt()
  270.   time()
  271.   line()
  272.   logsW()
  273.  
  274.   if command == "help" then
  275.     helpCommand()
  276.   elseif command == "core left on" then
  277.     core("Left","ON",colors.green)
  278.   elseif command == "core left off" then
  279.     core("Left","OFF",colors.red)
  280.   elseif command == "core right on" then
  281.     core("Right","ON",colors.green)
  282.   elseif command == "core right off" then
  283.     core("Right","OFF",colors.red)
  284.   elseif command == "clear" then
  285.     termClear()
  286.   elseif command == "energy amount" then
  287.     energyAmount()
  288.   elseif command == "stop" then
  289.     stop()
  290.   elseif command == "run" then
  291.     run()
  292.   elseif command == "/logs" then
  293.     shell.openTab("logRead")
  294.     shell.switchTab(2)
  295.   else
  296.     ttc(colors.red)
  297.     write(" Unknown command try help")
  298.     line()
  299.   end
  300.    
  301. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement