Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers зарядчик by serafim
- pastebin.com/mtKbYn42 update 22.11.19
- Зарядчик для электроинструмента
- использование:
- перед роботом поставить эндер-сундук,
- справа от робота зарядку
- требования:
- инвентарь,контроллер инвентаря
- пример запуска:
- charge
- ]]--
- local computer = require("computer")
- local term = require("term")
- local com = require('component')
- if not com.isAvailable("robot") then
- print("только роботы могут использовать эту программу")
- os.exit()
- end
- local r = require("robot")
- local invsize = r.inventorySize()
- if not com.isAvailable("inventory_controller") then
- print("для работы нужен контроллер инвентаря")
- os.exit()
- end
- local i_c = com.inventory_controller
- --тревога
- local function alert(message)
- print(message)
- r.setLightColor(0xFF0000)
- computer.beep(1000, 1)
- end
- --заряка инструмента
- local function chargetool()
- r.setLightColor(0xFFFFFF)
- term.clear()
- local inv = i_c.getInventorySize(3)
- if inv and inv > 4 then
- for i = 1, invsize do
- if r.count(i) > 0 then
- r.select(i)
- if not r.drop() then
- alert("в сундуке нет места !")
- return
- end
- end
- end
- for slot = 1, inv do
- local item = i_c.getStackInSlot(3, slot)
- if item and item.charge ~= nil then
- if item.charge < 10000 then
- print("слот: "..slot.." заряд: "..item.charge)
- r.select(1)
- i_c.suckFromSlot(3, slot)
- r.turnRight()
- local inv = i_c.getInventorySize(3)
- if inv and inv <= 4 then
- if not r.drop() then
- r.select(2)
- r.suck()
- r.turnLeft()
- if not r.drop() then
- alert("в сундуке нет места !")
- else
- print("скинул в сундук инструмент")
- r.select(1)
- break
- end
- else
- while true do
- print("жду зарядки инструмента...")
- os.sleep(20)
- local box = i_c.getStackInSlot(3, 1)
- if box and box.charge > item.charge then
- r.suck()
- r.turnLeft()
- if not r.drop() then
- alert("в сундуке нет места !")
- else
- r.setLightColor(0xFFFFFF)
- print("зарядил инструмент на: "..(box.charge-item.charge))
- break
- end
- else
- alert("инструмент не заряжается !")
- os.sleep(3)
- term.clear()
- end
- end
- end
- else
- alert("справа нет зарядчика !")
- r.turnLeft()
- end
- end
- end
- end
- else
- alert("нет сундука !")
- end
- end
- while true do
- chargetool()
- print("жду 30 секунд...")
- os.sleep(30)
- end
Add Comment
Please, Sign In to add comment