Guest User

ComputerCraft Machines states

a guest
Sep 5th, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. --CONFIG--
  2. side = "bottom"
  3.  
  4. --FUNCTIONS--
  5. function Clear()
  6. term.clear()
  7. term.setCursorPos(1, 1)
  8. end
  9.  
  10. function saveState()
  11. file = fs.open("state", "w")
  12. file.writeLine((colors.test(rs.getBundledOutput(side), colors.white)))
  13. file.writeLine((colors.test(rs.getBundledOutput(side), colors.orange)))
  14. file.writeLine((colors.test(rs.getBundledOutput(side), colors.magenta)))
  15. file.writeLine((colors.test(rs.getBundledOutput(side), colors.lightBlue)))
  16. file.close()
  17. end
  18.  
  19. function loadState()
  20. file = fs.open("state", "r")
  21. shell.run("redset", side, "white", file.readLine())
  22. shell.run("redset", side, "orange", file.readLine())
  23. shell.run("redset", side, "magenta", file.readLine())
  24. shell.run("redset", side, "lightBlue", file.readLine())
  25. file.close()
  26. end
  27.  
  28. --CODE--
  29. Clear()
  30. print("N1ghtK1n9's Computer")
  31. loadState()
  32. term.setCursorPos(1, 3)
  33. write"> "
  34. input = read()
  35. if input == ("engines") then
  36. shell.run("redset", side, "white", tostring(not colors.test(rs.getBundledOutput(side), colors.white)))
  37. Clear()
  38.     outE = rs.testBundledInput(side, colors.white)
  39.     if outE == true then
  40.     print("Turning Engines Off")
  41.     rs.setBundledOutput(side, colors.white)
  42.     elseif outE == false then
  43.     print("Turning Engines On")
  44.     rs.setBundledOutput(side, colors.white)
  45.     end
  46.     saveState()
  47.     sleep(1)
  48.     os.reboot()
  49.    
  50. elseif input == ("refineries") then
  51. shell.run("redset", side, "orange", tostring(not colors.test(rs.getBundledOutput(side), colors.orange)))
  52. Clear()
  53.     outR = rs.testBundledInput(side, colors.orange)
  54.     if outR == true then
  55.     print("Turning Refineries Off")
  56.     rs.setBundledOutput(side, colors.orange)
  57.     elseif outR == false then
  58.     print("Turning Refineries On")
  59.     rs.setBundledOutput(side, colors.orange)
  60.     saveState()
  61.     sleep(1)
  62.     os.reboot()
  63.     end
  64.  
  65. elseif input == ("geothermal") then
  66. shell.run("redset", side, "magenta", tostring(not colors.test(rs.getBundledOutput(side), colors.magenta)))
  67. Clear()
  68.     outG = rs.testBundledInput(side, colors.magenta)
  69.     if outG == true then
  70.     print("Turning Geothermal Generators Off")
  71.     rs.setBundledOutput(side, colors.magenta)
  72.     elseif outG == false then
  73.     print("Turning Geothermal Generators Off")
  74.     rs.setBundledOutput(side, colors.magenta)
  75.     saveState()
  76.     sleep(1)
  77.     os.reboot()
  78.     end
  79.    
  80. elseif input == "enginecoolant" then
  81. shell.run("redset", side, "lightBlue", tostring(not colors.test(rs.getBundledOutput(side), colors.lightBlue)))
  82. Clear()
  83.     outEC = rs.testBundledInput(side, colors.lightBlue)
  84.     if outEC == true then
  85.     print("Warning!! Are you sure you want to do this?")
  86.         input = read()
  87.         if input == "yes" then
  88.         print("Turning Engine Coolant Off")
  89.         rs.setBundledOutput(side, colors.lightBlue)
  90.         elseif input == "no" then
  91.         print("Leaving Coolant On")
  92.         Clear()
  93.         end
  94.     elseif outEC == false then
  95.     print("Turning Engine Coolant On")
  96.     rs.setBundledOutput(side, colors.lightBlue)
  97.     saveState()
  98.     sleep(1)
  99.     os.reboot()
  100.     end
  101.  
  102. elseif input == "reboot" then  
  103. os.reboot()
  104. end
Advertisement
Add Comment
Please, Sign In to add comment