agot137

slave_setup.lua

Apr 25th, 2026 (edited)
2,995
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. local CONFIG_FILE = "slave.cfg"
  2. local MODEM_SIDE = "bottom"
  3.  
  4. local config = {
  5. routes = {
  6. green = { activeSides = {}, inactiveSides = {} },
  7. blue = { activeSides = {}, inactiveSides = {} },
  8. red = { activeSides = {}, inactiveSides = {} },
  9. purple = { activeSides = {}, inactiveSides = {} },
  10. }
  11. }
  12.  
  13. local routeKeys = { "green", "blue", "red", "purple" }
  14. local routeNames = {
  15. green = "Zold",
  16. blue = "Kek",
  17. red = "Piros",
  18. purple = "Lila",
  19. }
  20.  
  21. local function loadConfig()
  22. if not fs.exists(CONFIG_FILE) then return end
  23. local h = fs.open(CONFIG_FILE, "r")
  24. local raw = h.readAll()
  25. h.close()
  26. local t = textutils.unserialize(raw)
  27. if type(t) == "table" then config = t end
  28. end
  29.  
  30. local function saveConfig()
  31. local h = fs.open(CONFIG_FILE, "w")
  32. h.write(textutils.serialize(config))
  33. h.close()
  34. end
  35.  
  36. local function splitSides(text)
  37. local out = {}
  38. for part in string.gmatch((text or ""), "[^,%s]+") do
  39. if part ~= MODEM_SIDE then table.insert(out, part) end
  40. end
  41. return out
  42. end
  43.  
  44. local function listSides(t)
  45. if not t or #t == 0 then return "(nincs)" end
  46. return table.concat(t, ",")
  47. end
  48.  
  49. local function clearAll()
  50. for _, side in ipairs({ "top", "left", "right", "front", "back" }) do
  51. redstone.setOutput(side, false)
  52. end
  53. end
  54.  
  55. local function pulse(list)
  56. clearAll()
  57. for _, side in ipairs(list or {}) do
  58. redstone.setOutput(side, true)
  59. end
  60. sleep(1)
  61. clearAll()
  62. end
  63.  
  64. loadConfig()
  65.  
  66. while true do
  67. term.setBackgroundColor(colors.black)
  68. term.setTextColor(colors.white)
  69. term.clear()
  70. term.setCursorPos(1,1)
  71. print("ROUTE SLAVE SETUP")
  72. print("=================")
  73. print("Computer ID: " .. os.getComputerID())
  74. print("Modem oldal: " .. MODEM_SIDE)
  75. print("Alaphelyzet: egyenes / nincs redstone")
  76. print("")
  77. for _, key in ipairs(routeKeys) do
  78. local r = config.routes[key]
  79. print(routeNames[key] .. " aktiv: " .. listSides(r.activeSides))
  80. print(routeNames[key] .. " egyenes: " .. listSides(r.inactiveSides))
  81. end
  82. print("")
  83. print("1 - Route szerkesztese")
  84. print("2 - Aktiv route teszt")
  85. print("3 - Egyenes teszt")
  86. print("4 - Mentes")
  87. print("5 - Kilepes")
  88. print("")
  89. write("> ")
  90. local cmd = read()
  91.  
  92. if cmd == "1" then
  93. write("Route key (green/blue/red/purple): ")
  94. local key = read()
  95. if config.routes[key] then
  96. write("Aktiv oldalak (pl top,left): ")
  97. config.routes[key].activeSides = splitSides(read())
  98. write("Egyenes oldalak (uresen hagyhatod): ")
  99. config.routes[key].inactiveSides = splitSides(read())
  100. end
  101. elseif cmd == "2" then
  102. write("Route key (green/blue/red/purple): ")
  103. local key = read()
  104. if config.routes[key] then
  105. print("1 mp aktiv teszt")
  106. pulse(config.routes[key].activeSides)
  107. end
  108. elseif cmd == "3" then
  109. print("1 mp egyenes teszt")
  110. clearAll()
  111. sleep(1)
  112. elseif cmd == "4" then
  113. saveConfig()
  114. print("Mentve")
  115. sleep(1)
  116. elseif cmd == "5" then
  117. clearAll()
  118. term.clear()
  119. term.setCursorPos(1,1)
  120. print("Kilepes")
  121. break
  122. end
  123. end
  124.  
Advertisement
Comments
  • User was banned
    • User was banned
  • User was banned
    • User was banned
Add Comment
Please, Sign In to add comment