giintv

Untitled

Aug 5th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1.  
  2.  
  3. reactor_pos = nil
  4. sides = {"top" , "bottom" , "front" , "left" , "right" , "back"}
  5. reactor_file = "reactor.txt"
  6.  
  7. function clear()
  8. term.setBackgroundColor(colors.green)
  9. term.clear()
  10. return nil
  11. end
  12.  
  13.  
  14. function newline()
  15. local x, y = term.getCursorPos()
  16. term.setCursorPos(x, y + 1)
  17. end
  18.  
  19. function setReactorPos()
  20. clear()
  21. term.setCursorPos(15, 7)
  22. term.write("Select reactor possition")
  23. term.setCursorPos(15, 8)
  24. term.write("1: Top, 2: Bot, 3: Front")
  25. term.setCursorPos(15, 9)
  26. term.write("4: Left, 5: Right, 6: Back")
  27. term.setCursorPos(15, 10)
  28. reactor_pos = tonumber(read())
  29. local file = fs.open(reactor_file, "w")
  30. file.write(reactor_pos)
  31. flie.close()
  32. end
  33.  
  34. function DetectPeripheral(name)
  35. for i = 1, 6 do
  36. if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == name then
  37. return sides[i]
  38. end
  39. end
  40. return nil
  41. end
  42.  
  43.  
  44. function rednetControll()
  45. while true do
  46. wifi = DetectPeripheral("modem")
  47. rednet.open(wifi)
  48. a, b, c = rednet.receive()
  49. return b;
  50. end
  51. end
  52.  
  53. function keyControll()
  54. while true do
  55. local sEvent, param = os.pullEvent("key")
  56. if sEvent == "key" then
  57. if param == "45" then
  58. if redstone.getOutput(reactor_pos) then
  59. return "stop"
  60. else
  61. return "start"
  62. end
  63. end
  64. end
  65. end
  66. end
  67.  
  68. function Menu()
  69. clear()
  70. term.setCursorPos(19, 8)
  71. if redstone.getOutput(sides[reactor_pos]) then
  72. term.write("ALL WORKS!")
  73. else
  74. term.write("NOTHING WORKS!")
  75. end
  76. term.setCursorPos(15, 9)
  77. term.write("REACTOR IS ON "..sides[reactor_pos])
  78. term.setCursorPos(15, 10)
  79. term.write("PRESS X TO CHANGE")
  80.  
  81. end
  82. --
  83.  
  84. if not fs.exists(reactor_file) then
  85. setReactorPos()
  86. else
  87. local file = fs.open(reactor_file, "r")
  88. reactor_pos = sides[tonumber(fs.readAll())]
  89. file.close()
  90. end
  91.  
  92. while true do
  93. command, id = parallel.waitForAny(rednetControll, keyControll, Menu)
  94. if command == "start" then
  95. redstone.setOutput(reactor_pos, 1)
  96. if not id == nil then
  97. rednet.send(id, true)
  98. end
  99. elseif command == "stop" then
  100. redstone.setOutput(reactor_pos, 0)
  101. if not id == nil then
  102. rednet.send(id, false)
  103. end
  104. elseif command == "state" then
  105. rednet.send(id, redstone.getOutput(reactor_pos))
  106. end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment