Advertisement
serafim7

mob grinder [OpenComputers]

Jul 26th, 2016 (edited)
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. --[[ OpenComputers  mob grinder by serafim
  2.      pastebin.com/gWdTfZu1 update 12.06.20
  3.  
  4. Робот атакует мобов перед собой,
  5. складывает лут в сундук под собой.
  6.  
  7. Слоты 1-4 заняты под лут с мобов.
  8. В инвентарь робота положить запасные мечи и уголь.
  9.  
  10. Требования:
  11. инвентарь, контроллер инвентаря, генератор.
  12. ]]--
  13.  
  14. local com = require('component')
  15. local computer = require("computer")
  16. local term = require("term")
  17. local event = require("event")
  18.  
  19. local atac,drop_count = 0,0
  20.  
  21. if not com.isAvailable("robot") then
  22.   print("только роботы могут использовать эту программу")
  23.   os.exit()
  24. end
  25. local r = require("robot")
  26.  
  27. if not com.isAvailable("inventory_controller") then
  28.   print("для работы нужен контроллер инвентаря")
  29.   os.exit()
  30. end
  31. local i_c = com.inventory_controller
  32.  
  33. if com.isAvailable("generator") then
  34.   gen = require("component").generator
  35.   gen_inst = true
  36. end
  37.  
  38. --поиск предмета в инвентаре робота
  39. local function slotitem(name)
  40.   for i = 1, r.inventorySize() do
  41.     local item = i_c.getStackInInternalSlot(i)
  42.     if item and string.find(item.name,name) then
  43.       r.select(i)
  44.       return true
  45.     end
  46.   end
  47.   return false
  48. end
  49.  
  50. --тревога
  51. local function alert(message)
  52.   term.clear()
  53.   print(message)
  54.   r.setLightColor(0xFF0000)
  55.   computer.beep(1000, 1)
  56.   local e = event.pull(5)
  57.   if e == "key_down" then
  58.     print("программа завершена")
  59.     os.exit()
  60.   end
  61. end
  62.  
  63. --атакуем
  64. local function attack()
  65.   while event.pull(1) ~= "key_down" do
  66.     if gen_inst and computer.energy() < 10000 then
  67.       if slotitem("coal") then
  68.         gen.insert()
  69.         term.clear()
  70.         print("заправился, угля в генераторе = "..gen.count())
  71.         os.sleep(1)
  72.       else
  73.         alert("нет угля в инвентаре робота !")
  74.       end
  75.     end
  76.     if computer.energy() < 5000 then
  77.       alert("мало энергии !")
  78.     end
  79.     if r.durability() == nil then
  80.       if slotitem("sword") then
  81.         i_c.equip()
  82.         term.clear()
  83.         print("взял запасной меч")
  84.         os.sleep(1)
  85.       else
  86.         alert("нет меча :(")
  87.         attack()
  88.       end
  89.     end
  90.     for i = 1, 4 do
  91.       if r.count(i) > 0 then
  92.         r.select(i)
  93.         drop_count = drop_count + r.count(i)
  94.         if not r.dropDown() then
  95.           alert("в сундуке нет места :(")
  96.           attack()
  97.         end
  98.       end
  99.     end
  100.     r.select(1)
  101.     r.setLightColor(0xFFFFFF)
  102.     term.clear()
  103.     print("всего лута сложено : "..drop_count)
  104.     print("всего атаковано    : "..atac)
  105.     while r.detect() do
  106.       r.swing()
  107.       atac = atac + 1
  108.       r.setLightColor(0xFF00FF)
  109.     end
  110.   end
  111. end
  112.  
  113. attack()
  114. print("программа завершена")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement