stairs-multi.lua

69 lines · 1.7 KB

Open raw

Send stairs jobs to multiple turtles

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/stairs-multi.lua
1-- stairs-multi.lua - Send stairs jobs to multiple turtles
2local function findModem()
3 for _, side in pairs(rs.getSides()) do
4 if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
5 return side
6 end
7 end
8 error("No modem found!")
9end
10
11rednet.open(findModem())
12
13-- Simple prompts
14print("Multi-Turtle Stairs")
15write("Turtle IDs (space-separated): ")
16local idStr = read()
17local ids = {}
18for id in idStr:gmatch("%S+") do
19 local num = tonumber(id)
20 if num then table.insert(ids, num) end
21end
22
23if #ids == 0 then
24 print("No valid turtle IDs")
25 return
26end
27
28write("Headroom (blocks above steps) [3]: ")
29local headroom = tonumber(read()) or 3
30
31write("Direction (u/d) [u]: ")
32local dir = string.lower(read())
33if dir == "d" then dir = "down" else dir = "up" end
34
35local length = ""
36if dir == "down" then
37 write("Depth (steps down) [32]: ")
38 length = tostring(tonumber(read()) or 32)
39else
40 write("Length - steps/surface/auto [surface]: ")
41 local lengthInput = string.lower(read())
42 if lengthInput ~= "" and lengthInput ~= "surface" then
43 if lengthInput == "auto" then
44 length = "auto"
45 else
46 local num = tonumber(lengthInput)
47 if num then
48 length = tostring(num)
49 end
50 end
51 end
52end
53
54write("Place floor blocks? (y/n) [n]: ")
55local place = string.lower(read()) == "y" and "place" or ""
56
57-- Build command
58local cmd = tostring(headroom) .. " " .. dir
59if length ~= "" then cmd = cmd .. " " .. length end
60if place ~= "" then cmd = cmd .. " " .. place end
61
62-- Send to turtles
63print("Sending to " .. #ids .. " turtles: stairs " .. cmd)
64for _, id in ipairs(ids) do
65 rednet.send(id, {command = "RUN", args = cmd})
66 print("Sent to turtle " .. id)
67end
68
69print("Jobs sent!")