multi.lua
70 lines · 1.7 KB
Send stairs jobs to multiple turtles
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/stairs/multi.lua
| 1 | -- multi.lua - Send stairs jobs to multiple turtles |
| 2 | local 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!") |
| 9 | end |
| 10 | |
| 11 | rednet.open(findModem()) |
| 12 | |
| 13 | -- Simple prompts |
| 14 | print("Multi-Turtle Stairs") |
| 15 | write("Turtle IDs (space-separated): ") |
| 16 | local idStr = read() |
| 17 | local ids = {} |
| 18 | for id in idStr:gmatch("%S+") do |
| 19 | local num = tonumber(id) |
| 20 | if num then table.insert(ids, num) end |
| 21 | end |
| 22 | |
| 23 | if #ids == 0 then |
| 24 | print("No valid turtle IDs") |
| 25 | return |
| 26 | end |
| 27 | |
| 28 | write("Headroom (blocks above steps) [3]: ") |
| 29 | local headroom = tonumber(read()) or 3 |
| 30 | |
| 31 | write("Direction (u/d) [u]: ") |
| 32 | local dir = string.lower(read()) |
| 33 | if dir == "d" then dir = "down" else dir = "up" end |
| 34 | |
| 35 | local length = "" |
| 36 | if dir == "down" then |
| 37 | write("Depth (steps down) [32]: ") |
| 38 | length = tostring(tonumber(read()) or 32) |
| 39 | else |
| 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 |
| 52 | end |
| 53 | |
| 54 | write("Place floor blocks? (y/n) [n]: ") |
| 55 | local place = string.lower(read()) == "y" and "place" or "" |
| 56 | |
| 57 | -- Build command |
| 58 | local cmd = tostring(headroom) .. " " .. dir |
| 59 | if length ~= "" then cmd = cmd .. " " .. length end |
| 60 | if place ~= "" then cmd = cmd .. " " .. place end |
| 61 | |
| 62 | -- Send to turtles |
| 63 | print("Sending to " .. #ids .. " turtles: stairs " .. cmd) |
| 64 | for _, id in ipairs(ids) do |
| 65 | rednet.send(id, {command = "RUN", args = cmd}) |
| 66 | print("Sent to turtle " .. id) |
| 67 | end |
| 68 | |
| 69 | print("Jobs sent!") |
| 70 |