Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers строитель платформы by serafim
- pastebin.com/Zd7W93nb update 02.07.21
- W
- *****
- *****L
- ^****
- пример сборки:
- https://i.imgur.com/ApLjvMq.png
- требования:
- корпус второго уровня (золотой) + процессор второго уровня
- улучшение инвентарь, лучше 3
- генератор по желанию
- улучшение парение, если робот будет строить над пропастью
- контейнер для апгрейда, если хотите использовать чанклоадер
- использование:
- закинуть в инвентарь робота блоки + уголь
- программа принимает атрибуты например: p 16 10
- ]]--
- local a = {...}
- local width = tonumber(a[1]) or 16 --ширина
- local length = tonumber(a[2]) or 16 --длина
- local event = require("event")
- local com = require('component')
- local computer = require("computer")
- local timestart = computer.uptime()
- local fuelinv,turn = true
- if not com.isAvailable("robot") then
- print("только роботы могут использовать эту программу")
- os.exit()
- end
- local r = require("robot")
- local inv = r.inventorySize()
- if com.isAvailable("generator") then
- gen = require("component").generator
- gen_inst = true
- end
- --статус
- local function status(msg)
- print("[ "..os.date("%H:%M:%S",computer.uptime()-timestart).." ] "..msg)
- end
- --чанк лоадер
- local function chunkload(state)
- if com.isAvailable("chunkloader") then
- if state then
- com.chunkloader.setActive(true)
- status("чанк лоадер активен")
- else
- com.chunkloader.setActive(false)
- status("чанк лоадер деактивирован")
- end
- end
- end
- --дозаправка углём
- local function checkfuel()
- if gen_inst then
- local gencount = gen.count()
- if gencount < 10 then
- local slot = r.select()
- for i = 1,inv do
- if r.count(i) > 0 then
- r.select(i)
- gen.insert()
- end
- end
- r.select(slot)
- if gen.count() > gencount then
- fuelinv = true
- status("заправился, угля в генераторе = "..gen.count())
- elseif fuelinv then
- fuelinv = false
- status("нет угля в инвентаре робота !!!")
- r.setLightColor(0xFF0000)
- computer.beep(1000, 1)
- end
- end
- end
- if computer.energy() <= 5000 then
- status("мало энергии !!!")
- r.setLightColor(0xFF0000)
- computer.beep(1000, 1)
- else
- r.setLightColor(0xFFFFFF)
- end
- end
- --ставим блок под роботом
- local function place()
- if r.count() == 0 then
- for slot = 1,inv do
- if r.count(slot) > 0 then
- r.select(slot)
- break
- end
- if slot == inv then
- status("в инвентаре нет блоков !!!")
- r.setLightColor(0xFF0000)
- computer.beep(1000, 1)
- chunkload(false)
- while true do
- local e = ({event.pull("inventory_changed")})[2]
- if r.count(e) > 0 then
- r.select(e)
- break
- end
- end
- status("ожидаю блоки...")
- while true do
- if event.pull(3,"inventory_changed") then
- os.sleep(3)
- else
- break
- end
- end
- chunkload(true)
- r.setLightColor(0xFFFFFF)
- status("продолжаю строить...")
- end
- end
- end
- r.placeDown()
- end
- --движемся вперед
- local function forward()
- while not r.forward() do
- r.swing()
- end
- end
- os.execute("cls")
- r.setLightColor(0xFFFFFF)
- status("ширина "..width.." длина "..length)
- chunkload(true)
- status("строю платформу...")
- for x = 1,width do
- checkfuel()
- for y = 1,length-1 do
- place()
- forward()
- end
- place()
- if x == width then
- break
- elseif x % 2 == 0 then
- turn = r.turnLeft
- else
- turn = r.turnRight
- end
- turn()
- forward()
- turn()
- end
- status("готово :)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement