Advertisement
Asioron

Ribolov

Jan 11th, 2016
1,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | None | 0 0
  1. ---------------------------------------------------------
  2. --                    Программа                        --  
  3. -- для автоматической ловли рыбы или хлама в Майнкрафт --
  4. --          на роботе из мода OpenComputers            --  
  5. --          проект http://computercraft.ru             --  
  6. --                 2016, © Asior                       --  
  7. ---------------------------------------------------------
  8.  
  9. ----------------ПЕРЕМЕННЫЕ-------------------
  10. local event = require("event")
  11. local r = require('robot')
  12. local computer = require("computer")
  13. err = false
  14. slots = 16;
  15.  
  16. --------------ПРОЦЕДУРЫ----------------------
  17.  
  18. function instrument()--сканирует первый слот инвентаря на наличие в нем удочки
  19.   if incontrol.getStackInInternalSlot(1)~=nil then
  20.     if incontrol.getStackInInternalSlot(1).name=='minecraft:fishing_rod' then
  21.       incontrol.equip()
  22.     end
  23.   else
  24.     print('У меня закончились удочки, или произошла неизвестная ошибка')
  25.     computer.beep(2000, 10)
  26.     os.sleep(20)
  27.   end
  28. end
  29.  
  30. function lovka()--функция ловли рыбы(или хлама)
  31.   r.use(0, true, 1)
  32.   os.sleep(3)
  33.   print('Ловись рыбка большая и маленькая...')
  34.   _ = event.pull(60,'redstone_changed')
  35.   r.use(0, true, 1)
  36.   print('УРА! чего-то клюнуло ... или показалось...')
  37.   os.sleep(2)
  38.   if redstone.getInput(0) > 0 then r.use(0, true, 1) end
  39.   os.sleep(1)
  40. end
  41.  
  42. -----------------ОСНОВНОЙ КОД-----------------
  43. print('Подключение устройств...')
  44. if require("component").isAvailable("redstone") then
  45.   redstone = require("component").redstone
  46.   print('Плата красного камня успешно подключена')
  47. else
  48.   print("Плата красного камня не обнаружена!")
  49.   print("Вы забыли установить плату красного камня, работа без неё невозможна, установите отсутствующее устройство и перезагрузите программу")
  50.   os.exit()
  51. end
  52.  
  53. if require("component").isAvailable("inventory_controller") then
  54.   incontrol = require("component").inventory_controller
  55.   print('Контроллер успешно подключен')
  56. else
  57.   print("Контроллер не обнаружен!")
  58.   print("Вы забыли установить контроллер инвентаря, работа без него возможна, но некоторые функции будут недоступны."..' \n '..'Продолжить работу? (1-да, 0-нет')
  59.   a = io.read(1)
  60.   if a == '1' then
  61.     print('Продолжаем работать, положите в руку удочку.')
  62.     print('Внимание! Как только удочка поломается, робот будет отключен!')
  63.     print('Жду удочку 10 секунд')
  64.     os.sleep(10)
  65.     err = true;
  66.   else
  67.     print('Выход...')
  68.     os.exit()
  69.   end
  70. end
  71.  
  72. while true do
  73.   if (r.durability() ~= nil) and (r.count(slots) == 0) then --проверка целостности предмета и пустоты инвенторя
  74.     lovka()
  75.   else
  76.     for i = 1, slots, 1 do
  77.       r.select(i)
  78.       r.dropDown(64)
  79.     end
  80.     r.select(1)
  81.     if r.durability() == nil then
  82.       if err == false then
  83.         r.suckUp() 
  84.         instrument()
  85.       else
  86.         print('Сломан инструмент, или его забыли мне дать')
  87.             computer.beep(2000, 5)
  88.             computer.shutdown()
  89.       end
  90.     end
  91.   end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement