Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ OpenComputers mob grinder by serafim
- pastebin.com/gWdTfZu1 update 12.06.20
- Робот атакует мобов перед собой,
- складывает лут в сундук под собой.
- Слоты 1-4 заняты под лут с мобов.
- В инвентарь робота положить запасные мечи и уголь.
- Требования:
- инвентарь, контроллер инвентаря, генератор.
- ]]--
- local com = require('component')
- local computer = require("computer")
- local term = require("term")
- local event = require("event")
- local atac,drop_count = 0,0
- if not com.isAvailable("robot") then
- print("только роботы могут использовать эту программу")
- os.exit()
- end
- local r = require("robot")
- if not com.isAvailable("inventory_controller") then
- print("для работы нужен контроллер инвентаря")
- os.exit()
- end
- local i_c = com.inventory_controller
- if com.isAvailable("generator") then
- gen = require("component").generator
- gen_inst = true
- end
- --поиск предмета в инвентаре робота
- local function slotitem(name)
- for i = 1, r.inventorySize() do
- local item = i_c.getStackInInternalSlot(i)
- if item and string.find(item.name,name) then
- r.select(i)
- return true
- end
- end
- return false
- end
- --тревога
- local function alert(message)
- term.clear()
- print(message)
- r.setLightColor(0xFF0000)
- computer.beep(1000, 1)
- local e = event.pull(5)
- if e == "key_down" then
- print("программа завершена")
- os.exit()
- end
- end
- --атакуем
- local function attack()
- while event.pull(1) ~= "key_down" do
- if gen_inst and computer.energy() < 10000 then
- if slotitem("coal") then
- gen.insert()
- term.clear()
- print("заправился, угля в генераторе = "..gen.count())
- os.sleep(1)
- else
- alert("нет угля в инвентаре робота !")
- end
- end
- if computer.energy() < 5000 then
- alert("мало энергии !")
- end
- if r.durability() == nil then
- if slotitem("sword") then
- i_c.equip()
- term.clear()
- print("взял запасной меч")
- os.sleep(1)
- else
- alert("нет меча :(")
- attack()
- end
- end
- for i = 1, 4 do
- if r.count(i) > 0 then
- r.select(i)
- drop_count = drop_count + r.count(i)
- if not r.dropDown() then
- alert("в сундуке нет места :(")
- attack()
- end
- end
- end
- r.select(1)
- r.setLightColor(0xFFFFFF)
- term.clear()
- print("всего лута сложено : "..drop_count)
- print("всего атаковано : "..atac)
- while r.detect() do
- r.swing()
- atac = atac + 1
- r.setLightColor(0xFF00FF)
- end
- end
- end
- attack()
- print("программа завершена")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement