Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. -- Config
  2.  
  3. isDiselGen = true
  4. redstoneControl = false
  5. redstoneOutputSide = "left"
  6. requiredPowerGenLevel = 4
  7. modemPos = "top"
  8. xOffsett = -1
  9.  
  10.  
  11. -- end of config
  12.  
  13. local gen = peripheral.wrap("right")
  14. rednet.open(modemPos)
  15. local powerSpace = "No message received"
  16.  
  17. function cText(text, yPos, xOff)
  18. x,y = term.getSize()
  19. xPos = (x - string.len(text))/2 - xOffsett - xOff
  20. term.setCursorPos(xPos,yPos)
  21. print(text)
  22. end
  23.  
  24. function screen()
  25. term.clear()
  26. cText("PowerController by _TheSettler_", 2, 0)
  27. cText("Recived power gen level:" .. powerGenLevel, 4, 0)
  28. cText("Status: " .. status, 5, 0)
  29. end
  30.  
  31. function getUpdate()
  32. senderID, message, protocol = rednet.receive()
  33. if protocol == "powerGenLevel" then
  34. if message = 1 then
  35. powerGenLevel = 1
  36. elseif message = 2 then
  37. powerGenLevel = 2
  38. elseif message = 3 then
  39. powerGenLevel = 3
  40. elseif message = 4 then
  41. powerGenLevel = 4
  42. else
  43. status = "Error: No PowerLevel"
  44. end
  45. end
  46. if tostring(powerGenLevel) == "Error: No PowerLevel"
  47. break
  48. elseif requiredPowerGenLevel < powerGenLevel then
  49. status = "Activated"
  50. else
  51. status = "Deactivated"
  52. end
  53. controlPower()
  54. end
  55.  
  56. function isNumeric(value)
  57. if tonumber(value) ~= nil then
  58. return true
  59. else
  60. return false
  61. end
  62. end
  63.  
  64.  
  65. function controlPower()
  66. if isDiselGen = true then
  67. if status == "Activated" then
  68. gen.setEnabled(true)
  69. else
  70. gen.setEnabled(false)
  71. end
  72. end
  73. if redstoneControl = true then
  74. if status == "Activated" then
  75. redstone.setOutput(redstoneOutputSide, false)
  76. else
  77. redstone.setOutput(redstoneOutputSide, false)
  78. end
  79. end
  80. end
  81.  
  82.  
  83.  
  84. while true do
  85. screen()
  86. getUpdate()
  87. sleep(5)
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement