JoonBug03

ms_main

Nov 8th, 2026 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. local function relay_left(relay, relay_table)
  2. relay_table[relay].setOutput("left", true)
  3. os.sleep(0.1)
  4. relay_table[relay].setOutput("left", false)
  5. end
  6.  
  7. local function relay_top(relay,relay_table)
  8. relay_table[relay].setOutput("top", true)
  9. os.sleep(0.1)
  10. relay_table[relay].setOutput("top", false)
  11. end
  12.  
  13. local function relay_right(relay,relay_table)
  14. relay_table[relay].setOutput("right", true)
  15. os.sleep(0.1)
  16. relay_table[relay].setOutput("right", false)
  17. end
  18.  
  19. local raw_relays = { peripheral.find("redstone_relay")}
  20. local relays = {}
  21. local sides = {top = true, bottom = true, left = true, right = true, front = true, back = true}
  22.  
  23. for _, relay in ipairs(raw_relays) do
  24. local name = peripheral.getName(relay)
  25. if not sides[name] then
  26. table.insert(relays, relay)
  27. end
  28. end
  29.  
  30. table.sort(relays, function(a,b)
  31. local nameA = peripheral.getName(a)
  32. local nameB = peripheral.getName(b)
  33.  
  34. local idA = tonumber(nameA:match("%d+")) or 0
  35. local idB = tonumber(nameB:match("%d+")) or 0
  36.  
  37. return idA < idB
  38. end)
  39.  
  40. local events = {
  41. function() relay_left(1, relays) end,
  42. function() relay_top(1, relays) end,
  43. function() relay_right(1, relays) end,
  44. function() relay_left(2, relays) end,
  45. function() relay_top(2, relays) end,
  46. function() relay_right(2, relays) end
  47. }
  48.  
  49. local timing = {1,2,5,3,1,2}
  50.  
  51. local function run_show(start_point)
  52. for i = start_point, #timing do
  53. events[i]()
  54. os.sleep(timing[i])
  55. end
  56. end
  57.  
  58. local function test_relays()
  59. for i, relay in ipairs(relays) do
  60. local name = peripheral.getName(relay)
  61.  
  62. if name ~= "back" then
  63. relay.setOutput("top", true)
  64. os.sleep(0.1)
  65. relay.setOutput("top", false)
  66. relay.setOutput("left", true)
  67. os.sleep(0.1)
  68. relay.setOutput("left", false)
  69. relay.setOutput("right", true)
  70. os.sleep(0.1)
  71. relay.setOutput("right", false)
  72. end
  73. end
  74. end
  75.  
  76. local function print_relays()
  77. for i, relay in ipairs(relays) do
  78. print(string.format("[%d] %s", i, peripheral.getName(relay)))
  79. end
  80. end
  81.  
  82. local function main()
  83. print("Show controller ready.")
  84. print("Waiting for signal...")
  85.  
  86. while true do
  87. -- Wait until the front receives a redstone signal
  88. while not redstone.getInput("front") do
  89. os.pullEvent("redstone")
  90. end
  91.  
  92. print("Signal received! Starting show...")
  93.  
  94. run_show(1)
  95.  
  96. print("Show finished. Resetting...")
  97.  
  98. while redstone.getInput("front") do
  99. os.pullEvent("redstone")
  100. end
  101.  
  102. print("Ready for next show.")
  103. print("Waiting for signal...")
  104. end
  105. end
  106.  
  107. -- Start the program
  108. main()
Advertisement
Add Comment
Please, Sign In to add comment