serafim7

зарядчик электроинструмента [OpenComputers]

Nov 20th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. --[[  opencomputers зарядчик by serafim
  2. pastebin.com/mtKbYn42   update 22.11.19
  3.  
  4. Зарядчик для электроинструмента
  5.  
  6. использование:
  7. перед роботом поставить эндер-сундук,
  8. справа от робота зарядку
  9.  
  10. требования:
  11. инвентарь,контроллер инвентаря
  12.  
  13. пример запуска:
  14. charge
  15. ]]--
  16.  
  17. local computer = require("computer")
  18. local term = require("term")
  19. local com = require('component')
  20.  
  21. if not com.isAvailable("robot") then
  22.   print("только роботы могут использовать эту программу")
  23.   os.exit()
  24. end
  25. local r = require("robot")
  26. local invsize = r.inventorySize()
  27.  
  28. if not com.isAvailable("inventory_controller") then
  29.   print("для работы нужен контроллер инвентаря")
  30.   os.exit()
  31. end
  32. local i_c = com.inventory_controller
  33.  
  34. --тревога
  35. local function alert(message)
  36.   print(message)
  37.   r.setLightColor(0xFF0000)
  38.   computer.beep(1000, 1)
  39. end
  40.  
  41. --заряка инструмента
  42. local function chargetool()
  43.   r.setLightColor(0xFFFFFF)
  44.   term.clear()
  45.   local inv = i_c.getInventorySize(3)
  46.   if inv and inv > 4 then
  47.     for i = 1, invsize do
  48.       if r.count(i) > 0 then
  49.         r.select(i)
  50.         if not r.drop() then
  51.           alert("в сундуке нет места !")
  52.           return
  53.         end
  54.       end
  55.     end
  56.     for slot = 1, inv do
  57.       local item = i_c.getStackInSlot(3, slot)
  58.       if item and item.charge ~= nil then
  59.         if item.charge < 10000 then
  60.           print("слот: "..slot.." заряд: "..item.charge)
  61.           r.select(1)
  62.           i_c.suckFromSlot(3, slot)
  63.           r.turnRight()
  64.           local inv = i_c.getInventorySize(3)
  65.           if inv and inv <= 4 then
  66.             if not r.drop() then
  67.               r.select(2)
  68.               r.suck()
  69.               r.turnLeft()
  70.               if not r.drop() then
  71.                 alert("в сундуке нет места !")
  72.               else
  73.                 print("скинул в сундук инструмент")
  74.                 r.select(1)
  75.                 break
  76.               end
  77.             else
  78.               while true do
  79.                 print("жду зарядки инструмента...")
  80.                 os.sleep(20)
  81.                 local box = i_c.getStackInSlot(3, 1)
  82.                 if box and box.charge > item.charge then
  83.                   r.suck()
  84.                   r.turnLeft()
  85.                   if not r.drop() then
  86.                     alert("в сундуке нет места !")
  87.                   else
  88.                     r.setLightColor(0xFFFFFF)
  89.                     print("зарядил инструмент на: "..(box.charge-item.charge))
  90.                     break
  91.                   end
  92.                 else
  93.                   alert("инструмент не заряжается !")
  94.                   os.sleep(3)
  95.                   term.clear()
  96.                 end
  97.               end
  98.             end
  99.           else
  100.             alert("справа нет зарядчика !")
  101.             r.turnLeft()
  102.           end
  103.         end
  104.       end
  105.     end
  106.   else
  107.     alert("нет сундука !")
  108.   end
  109. end
  110.  
  111. while true do
  112.   chargetool()
  113.   print("жду 30 секунд...")
  114.   os.sleep(30)
  115. end
Add Comment
Please, Sign In to add comment