Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- drill_pult.lua — мини-пульт для теста бура/копания
- -- Команды:
- -- 1 / dig — копнуть ВПЕРЁД (robot.swing)
- -- 2 / suck — подобрать лут (вперёд/вниз/вверх)
- -- 3 / digd — копнуть ВНИЗ
- -- 4 / digu — копнуть ВВЕРХ
- -- e / equip — взять/убрать инструмент из выбранного слота в tool-слот
- -- f/b/u/d N — движение (по умолчанию 1)
- -- tl/tr/ta — повороты
- -- ad/af/au — анализ блока (вниз/вперёд/вверх; выведет name/label)
- -- help — список команд
- -- exit — выйти
- local robot = require("robot")
- local sides = require("sides")
- local term = require("term")
- local comp = require("component")
- local ic = comp.isAvailable("inventory_controller") and comp.inventory_controller or nil
- local geo = comp.isAvailable("geolyzer") and comp.geolyzer or nil
- local function many(fn, n, label)
- n = tonumber(n) or 1
- for i=1,n do
- if not fn() then
- print((label or "шаг").." #"..i.." не выполнен")
- break
- end
- end
- end
- local function analyze(side)
- if not geo then print("Нет geolyzer"); return end
- local d = geo.analyze(side) or {}
- print("ID:", d.name or "?", " Label:", d.label or "")
- end
- local function suckAll()
- robot.suck(); robot.suckDown(); robot.suckUp()
- end
- local function equipToggle()
- if not ic then print("Нет inventory_controller"); return end
- ic.equip() -- меняет местами выбранный слот и tool-слот
- end
- local function help()
- print("Команды:")
- print(" 1|dig - копнуть вперед")
- print(" 2|suck - подобрать лут (вперед/вниз/вверх)")
- print(" 3|digd - копнуть вниз")
- print(" 4|digu - копнуть вверх")
- print(" e|equip - equip: выбранный слот <-> tool-слот")
- print(" f/b/u/d n - движение (n по умолчанию 1)")
- print(" tl/tr/ta - повороты (лево/право/разворот)")
- print(" ad/af/au - анализ блока вниз/вперед/вверх")
- print(" help - помощь")
- print(" exit - выход")
- end
- term.clear()
- print("Пульт бур-теста. Введите 'help' для списка команд.")
- while true do
- io.write("> ")
- local line = io.read()
- if not line then break end
- local cmd, arg = line:match("^(%S+)%s*(.*)$")
- cmd = (cmd or ""):lower()
- if cmd=="" then
- elseif cmd=="exit" or cmd=="q" then break
- elseif cmd=="help" or cmd=="h" then help()
- -- копание
- elseif cmd=="1" or cmd=="dig" then robot.swing(); suckAll()
- elseif cmd=="2" or cmd=="suck" then suckAll()
- elseif cmd=="3" or cmd=="digd" then robot.swingDown(); suckAll()
- elseif cmd=="4" or cmd=="digu" then robot.swingUp(); suckAll()
- -- equip
- elseif cmd=="e" or cmd=="equip" then equipToggle()
- -- движение
- elseif cmd=="f" then many(robot.forward, arg, "вперед")
- elseif cmd=="b" then many(robot.back, arg, "назад")
- elseif cmd=="u" then many(robot.up, arg, "вверх")
- elseif cmd=="d" then many(robot.down, arg, "вниз")
- elseif cmd=="tl" then robot.turnLeft()
- elseif cmd=="tr" then robot.turnRight()
- elseif cmd=="ta" then robot.turnAround()
- -- анализ
- elseif cmd=="ad" then analyze(sides.down)
- elseif cmd=="af" then analyze(sides.front)
- elseif cmd=="au" then analyze(sides.up)
- else
- print("Неизвестная команда. help — список команд.")
- end
- end
- print("Выход.")
Advertisement
Add Comment
Please, Sign In to add comment