Advertisement
loccode

Kaktus

Jul 27th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local hw = fs.open("report", fs.exists("report") and "a" or "w")
  2. local hr = fs.open("report", fs.exists("report") and "r")
  3.  
  4. function welcome()
  5. print("Version 1.1")
  6. print("Skok dlina? (46)")
  7. length = read()
  8. num_lenght = tonumber(length)
  9. print("OK. Dlina ustanovlena: ", length)
  10. print("-----")
  11. print("Skok shirina?")
  12. width = read()
  13. num_width = tonumber(width)
  14. print("OK. Shirina ustanovlena: ", width)
  15. print("Write the side of the modem (left, right, front, back, bottom, top)")
  16. rednet_side = read()
  17. rednet.open(rednet_side)
  18.  
  19.  --Show total info about turtle settings
  20. print("~~~~~")
  21. print("Total info:")
  22. print("Length: ", length)
  23. print("Width: ", width)
  24. print("Fuel lvl: ", turtle.getFuelLevel())
  25. print("Rednet modem side: ", rednet_side)
  26. local x, y, z = gps.locate(5)
  27.  if not x then --If gps.locate didn't work, it won't return anything. So check to see if it did.
  28.    print("Failed to get my location!")
  29.  else
  30.    print("I am at (" .. x .. ", " .. y .. ", " .. z .. ")") --This prints 'I am at (1, 2, 3)' or whatever your coordinates are
  31.  end
  32. print("~~~~~")
  33.  
  34. end
  35.  
  36. function recive_commands(status, time )
  37. local senderId, message, protocol = rednet.receive(time)
  38. local fuel = turtle.getFuelLevel()
  39. local x, y, z = gps.locate(5)
  40. print (x,y,z)
  41. local report = {status, fuel}
  42. if senderId then
  43. print("Sender: ", senderId)
  44. print(message)
  45. else
  46. print("Waiting for cactus...")
  47. end
  48. if senderId == 4 then
  49.   if message == "status" then
  50.     rednet.send(tonumber(senderId), report)
  51.   end
  52.   end
  53. end
  54.  
  55. function collectStaff(num_width, num_lenght)
  56. while num_lenght > 0 do
  57. recive_commands("Collecting cactus...", 0.4)  
  58. turtle.suck()
  59. turtle.suckUp()
  60. turtle.suckDown()
  61. turtle.forward()
  62. num_lenght = num_lenght - 1;
  63. print("Ostalos xodov: ", num_lenght)
  64. if num_lenght < 1 then
  65. turtle.turnRight()
  66. while num_width > 1 do
  67. turtle.forward()
  68. num_width = num_width - 1;
  69. end
  70. turtle.turnRight()
  71. print("Povorachivayu obratno...")
  72. print("Fuel lvl: ", turtle.getFuelLevel())
  73. end
  74. end
  75. end
  76.  
  77. function make_circle()
  78. collectStaff(tonumber(width), tonumber(length))
  79. collectStaff(tonumber(width), tonumber(length))
  80. end
  81.  
  82. function sleeping()
  83. print("No cactus for now. Sleep for 20 sec...")
  84. sleep(20)
  85. --num_width = tonumber(width)
  86. --num_lenght = tonumber(length)
  87. end
  88.  
  89. --Here starts the initialization of the programm
  90.  
  91. --Show welcome message and settings
  92. welcome()
  93.  
  94. --Infinite loop for cheking the redstone signal for the turtle
  95. while true do
  96.  
  97. if redstone.getInput("back") then
  98. make_circle()
  99. else
  100. recive_commands("Waiting for cactus...", 5)
  101. end
  102.  
  103. end
  104.  
  105. --Here ends the initialization of the programm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement