Advertisement
serafim7

cobblestone generator [OpenComputers]

Aug 21st, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. --[[ opencomputers генератор булыжника by serafim  http://pastebin.com/YMvuJagz
  2.  
  3. !!! ВНИМАНИЕ !!! На сервере не использовать, получиш БАН :)
  4.  
  5. снизу робота сундук под булыжник
  6. в слоты со 2-го по 16 запасные кирки
  7.  
  8. требования:
  9. инвентарь,контроллер инвентаря.
  10. солнечная панель желательно.
  11. ]]--
  12.  
  13. local term = require("term")
  14. local com = require('component')
  15. local fs = require("filesystem")
  16. local cobble, takt, ext = 0, 0, 0
  17.  
  18. if not com.isAvailable("robot") then
  19.   print("только роботы могут использовать эту программу")
  20.   os.exit()
  21. end
  22. local r = require("robot")
  23.  
  24. if not com.isAvailable("inventory_controller") then
  25.   print("для работы нужен контроллер инвентаря")
  26.   os.exit()
  27. end
  28. local i_c = com.inventory_controller
  29.  
  30. if not fs.exists("cobblegen") then
  31.   file = io.open("cobblegen","w")
  32.   file:write(cobble)
  33.   file:close()
  34. end
  35.  
  36. local function openfile()
  37.   file = io.open("cobblegen","r")
  38.   ext = file:read()
  39.   file:close()
  40. end
  41.  
  42. local function stop(message)
  43.   print("\n"..message)
  44.   os.exit()
  45. end
  46.  
  47. local function pickaxe()
  48.   if r.durability() == nil then
  49.     local inv_size = r.inventorySize()
  50.     for i = 2, inv_size do
  51.       if r.count(i) == 1 then
  52.         r.select(i)
  53.         i_c.equip()
  54.         r.select(1)
  55.         term.clear()
  56.         print("взял запасную кирку")
  57.         os.sleep(1)
  58.         return false
  59.       else
  60.         if i == inv_size then
  61.           stop("нет кирки :(")
  62.         end
  63.       end
  64.     end
  65.   end
  66. end
  67.  
  68. local function drop()
  69.   if r.count(1) == 32 then
  70.     r.select(1)
  71.     if not r.dropDown(r.count(1)-1) then
  72.       stop("в сундуке нет места :(")
  73.     end
  74.   end
  75. end
  76.  
  77. r.select(1)
  78. openfile()
  79.  
  80. while true do
  81.   pickaxe()
  82.   if r.detect() then
  83.     r.swing()
  84.     cobble = cobble + 1
  85.     takt = takt + 1
  86.   end
  87.   drop()
  88.   term.clear()
  89.   print("за все время нарубил булыжника: "..ext.."\n".."в этот раз нарубил булыжника:   "..cobble)
  90.   if takt == 10 then
  91.     takt = ext + 10
  92.     file = io.open("cobblegen","w")
  93.     file:write(takt)
  94.     file:close()
  95.     takt = 0
  96.     openfile()
  97.   end
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement