Advertisement
serafim7

строитель платформы [OpenComputers]

Jul 2nd, 2021 (edited)
1,568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.27 KB | None | 0 0
  1. --[[ opencomputers строитель платформы by serafim
  2.      pastebin.com/Zd7W93nb        update 02.07.21
  3.    
  4.   W
  5. *****
  6. *****L
  7. ^****
  8.  
  9. пример сборки:
  10. https://i.imgur.com/ApLjvMq.png
  11.  
  12. требования:
  13. корпус второго уровня (золотой) + процессор второго уровня
  14. улучшение инвентарь, лучше 3
  15. генератор по желанию
  16. улучшение парение, если робот будет строить над пропастью
  17. контейнер для апгрейда, если хотите использовать чанклоадер
  18.  
  19. использование:
  20. закинуть в инвентарь робота блоки + уголь
  21. программа принимает атрибуты например: p 16 10
  22. ]]--
  23.  
  24. local a = {...}
  25. local width = tonumber(a[1]) or 16 --ширина
  26. local length = tonumber(a[2]) or 16 --длина
  27.  
  28. local event = require("event")
  29. local com = require('component')
  30. local computer = require("computer")
  31. local timestart = computer.uptime()
  32. local fuelinv,turn = true
  33.  
  34. if not com.isAvailable("robot") then
  35.   print("только роботы могут использовать эту программу")
  36.   os.exit()
  37. end
  38. local r = require("robot")
  39. local inv = r.inventorySize()
  40.  
  41. if com.isAvailable("generator") then
  42.   gen = require("component").generator
  43.   gen_inst = true
  44. end
  45.  
  46. --статус
  47. local function status(msg)
  48.   print("[ "..os.date("%H:%M:%S",computer.uptime()-timestart).." ] "..msg)
  49. end
  50.  
  51. --чанк лоадер
  52. local function chunkload(state)
  53.   if com.isAvailable("chunkloader") then
  54.     if state then
  55.       com.chunkloader.setActive(true)
  56.       status("чанк лоадер активен")
  57.     else
  58.       com.chunkloader.setActive(false)
  59.       status("чанк лоадер деактивирован")
  60.     end
  61.   end
  62. end
  63.  
  64. --дозаправка углём
  65. local function checkfuel()
  66.   if gen_inst then
  67.     local gencount = gen.count()
  68.     if gencount < 10 then
  69.       local slot = r.select()
  70.       for i = 1,inv do
  71.         if r.count(i) > 0 then
  72.           r.select(i)
  73.           gen.insert()
  74.         end
  75.       end
  76.       r.select(slot)
  77.       if gen.count() > gencount then
  78.         fuelinv = true
  79.         status("заправился, угля в генераторе = "..gen.count())
  80.       elseif fuelinv then
  81.         fuelinv = false
  82.         status("нет угля в инвентаре робота !!!")
  83.         r.setLightColor(0xFF0000)
  84.         computer.beep(1000, 1)
  85.       end
  86.     end
  87.   end
  88.   if computer.energy() <= 5000 then
  89.     status("мало энергии !!!")
  90.     r.setLightColor(0xFF0000)
  91.     computer.beep(1000, 1)
  92.   else
  93.     r.setLightColor(0xFFFFFF)
  94.   end
  95. end
  96.  
  97. --ставим блок под роботом
  98. local function place()
  99.   if r.count() == 0 then
  100.     for slot = 1,inv do
  101.       if r.count(slot) > 0 then
  102.         r.select(slot)
  103.         break
  104.       end
  105.       if slot == inv then
  106.         status("в инвентаре нет блоков !!!")
  107.         r.setLightColor(0xFF0000)
  108.         computer.beep(1000, 1)
  109.         chunkload(false)
  110.         while true do
  111.           local e = ({event.pull("inventory_changed")})[2]  
  112.           if r.count(e) > 0 then
  113.             r.select(e)
  114.             break
  115.           end
  116.         end
  117.         status("ожидаю блоки...")
  118.         while true do
  119.           if event.pull(3,"inventory_changed") then
  120.             os.sleep(3)
  121.           else
  122.             break
  123.           end
  124.         end
  125.         chunkload(true)
  126.         r.setLightColor(0xFFFFFF)
  127.         status("продолжаю строить...")
  128.       end
  129.     end
  130.   end
  131.   r.placeDown()
  132. end
  133.  
  134. --движемся вперед
  135. local function forward()
  136.   while not r.forward() do
  137.     r.swing()
  138.   end
  139. end
  140.  
  141. os.execute("cls")
  142. r.setLightColor(0xFFFFFF)
  143. status("ширина "..width.."  длина "..length)
  144. chunkload(true)
  145. status("строю платформу...")
  146. for x = 1,width do
  147.   checkfuel()
  148.   for y = 1,length-1 do
  149.     place()
  150.     forward()
  151.   end
  152.   place()
  153.   if x == width then
  154.     break
  155.   elseif x % 2 == 0 then
  156.     turn = r.turnLeft
  157.   else
  158.     turn = r.turnRight
  159.   end
  160.   turn()
  161.   forward()
  162.   turn()
  163. end
  164. status("готово :)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement