Advertisement
Fredyman_95

RAR

Oct 5th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. --[[
  2. Redstone Activated Rings
  3. v1.0.0.1
  4.  
  5. Created By: Fredyman_95
  6. ]]--
  7.  
  8. -- User settings ----------------------------------------------------
  9. ringsAddress = {} -- {"Amun", "Khepri", ... "Felluca"}
  10. pauseBetweenDials = 3 -- Period in s between program restart after rings finish transport
  11. rsSignal = east -- Choose one of: east, west, south, north, top, bottom
  12.  
  13. -- End of User settings ---------------------------------------------
  14.  
  15. -- Declarations -----------------------------------------------------
  16. local component = require("component")
  17. local computer = require("computer")
  18. local event = require("event")
  19. local sides = require("sides")
  20. local term = require("term")
  21. local forceStop = false
  22. -- End of Declarations ----------------------------------------------
  23.  
  24. -- Check of user settings and requirements --------------------------
  25. if type(pauseBetweenDials) ~= "number" then pauseBetweenDials = 3 end
  26. if pauseBetweenDials < 0 then pauseBetweenDials = 3 end
  27.  
  28. if component.isAvailable("transportrings") then
  29. rings = component.transportrings
  30. NumberOfRings = 0
  31. for k,v in component.list() do if v == "transportrings" then NumberOfRings = NumberOfRings + 1 end end
  32. if NumberOfRings > 1 then
  33. io.stderr:write("Too Many Transport Rings Connected to Computer.")
  34. computer.beep()
  35. os.exit(1)
  36. end
  37. else
  38. io.stderr:write("No Transport Rings Connected")
  39. computer.beep()
  40. os.exit(1)
  41. end
  42.  
  43. if component.isAvailable("redstone") then
  44. rs = component.redstone
  45. NumberOfRsIOs = 0
  46. for k,v in component.list() do if v == "redstone" then NumberOfRsIOs = NumberOfRsIOs + 1 end end
  47. if NumberOfRsIOs > 1 then
  48. io.stderr:write("Too Many Redstone Components Connected to Computer.(RedstoneIO or Redstone Card)")
  49. computer.beep()
  50. os.exit(1)
  51. end
  52. else
  53. io.stderr:write("No Redstone Component Installed. (RedstoneIO or Redstone Card)")
  54. computer.beep()
  55. os.exit(1)
  56. end
  57. -- End of Check of user settings-------------------------------------
  58.  
  59. -- Events -----------------------------------------------------------
  60. local function startEvents()
  61. eventsActive = true
  62. eventInterrupted = event.listen("interrupted", function() forceStop = true end)
  63. eventTeleportStart = event.listen("transportrings_teleport_start", function(_, address, caller, initiating) mainRSLoop = false rsLockDialed = true end)
  64. eventTeleportFinished = event.listen("transportrings_teleport_finished", function(_, address, caller, initiating) rsLockDialed = false end)
  65. end
  66.  
  67. local function cancelEvents()
  68. event.cancel(eventTeleportStart)
  69. event.cancel(eventTeleportFinished)
  70. event.cancel(eventInterrupted)
  71. eventsActive = false
  72. end
  73.  
  74. -- End of Events ----------------------------------------------------
  75.  
  76. -- Functions --------------------------------------------------------
  77. local function selectSide(rsSignal)
  78. if rsSignal == east then rsInput = sides.east
  79. elseif rsSignal == west then rsInput = sides.west
  80. elseif rsSignal == north then rsInput = sides.north
  81. elseif rsSignal == south then rsInput = sides.south
  82. elseif rsSignal == top then rsInput = sides.top
  83. elseif rsSignal == bottom then rsInput = sides.bottom end
  84. end
  85.  
  86. local function dialRings()
  87. rsLockDialed = true
  88. for i,v in pairs(ringsAddress) do
  89. if forceStop then break end
  90. symbol = ringsAddress[i]
  91. rings.addSymbolToAddress(0, symbol)
  92. os.sleep(0.5)
  93. end
  94. if forceStop == false then
  95. os.sleep(0.5)
  96. computer.beep()
  97. rings.addSymbolToAddress(0, 5)
  98. end
  99. end
  100.  
  101. -- End of Functions -------------------------------------------------
  102. selectSide(rsSignal)
  103. rings.addSymbolToAddress(0, 5)
  104. startEvents()
  105. ::start::
  106. term.clear()
  107. mainRSLoop = true
  108. rsLockDialed = false
  109.  
  110. print("Press button to activate Transport rings")
  111. while mainRSLoop do
  112. if forceStop then goto closeProgram end
  113. if rs.getInput(rsInput) > 0 then break end
  114. os.sleep(0.1)
  115. end
  116.  
  117. dialRings()
  118.  
  119. while rsLockDialed do
  120. if forceStop then goto closeProgram end
  121. os.sleep(0.1)
  122. end
  123.  
  124. os.sleep(pauseBetweenDials)
  125. goto start
  126. ::closeProgram::
  127. cancelEvents()
  128. print("All events listeners cancelled")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement