Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. --print("Nuclear Controller Active")
  2.  
  3. local reactorLoc = "1,-1,1"
  4. local threshold = 65
  5. local sensorSide = "top"
  6. local reactorSide = "back"
  7. local inputSide = "left"
  8.  
  9. function listener()
  10. --print("poop")
  11. while true do
  12. local event = os.pullEventRaw()
  13. --print("debug")
  14. if event == "terminate" then
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. print("Termination call detected")
  18. print("Powering off reactor")
  19. redstone.setOutput(reactorSide,false)
  20. print("Reactor powered off")
  21. return
  22. --else
  23. --print("received")
  24. end
  25. end
  26. end
  27.  
  28. os.loadAPI("ocs/apis/sensor")
  29. mySens = sensor.wrap(sensorSide)
  30. local reactorActive = false
  31. redstone.setOutput(reactorSide,false)
  32. --c1 = coroutine.create(listener)
  33. --coroutine.resume(c1)
  34. function MainFunct()
  35. while true do
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. print("Nuclear Controller Active")
  39. local deets = mySens.getTargetDetails(reactorLoc)
  40. local curTemp = deets["HeatPercentage"]
  41. if deets["Active"] then
  42. print("Reactor Active")
  43. else
  44. print("Reactor Inactive")
  45. end
  46. print("Reactor Heat at "..curTemp.."%")
  47. local input = redstone.getInput(inputSide)
  48. if (not reactorActive and curTemp < threshold and input) then
  49. reactorActive = true
  50. redstone.setOutput(reactorSide,true)
  51. elseif ((reactorActive and curTemp > threshold) or not input) then
  52. reactorActive = false
  53. redstone.setOutput(reactorSide,false)
  54. end
  55. os.sleep(0.05)
  56. end
  57. end
  58.  
  59. parallel.waitForAny(listener, MainFunct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement