Guest User

Untitled

a guest
Aug 18th, 2019
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local drone = component.proxy(component.list("drone")())
  2.  
  3. local FARM_DIRECTION_NS = 0
  4. local FARM_DIRECTION_EW = -1
  5. local FARM_WIDTH = 8
  6. local FARM_HEIGHT = 8
  7.  
  8. local function sleep(timeout)
  9. checkArg(1, timeout, "number", "nil")
  10. local deadline = computer.uptime() + (timeout or 0)
  11. repeat
  12. computer.pullSignal(deadline - computer.uptime())
  13. until computer.uptime() >= deadline
  14. end
  15.  
  16. local function checkE()
  17. local en = computer.energy()
  18. return en
  19. end
  20.  
  21. local function drop()
  22. drone.drop(2)
  23. end
  24.  
  25. local function dropAll()
  26. for i=4,2,-1
  27. do
  28. drone.select(i)
  29. drop()
  30. end
  31. drone.select(1)
  32. end
  33.  
  34. local function move(x,y,z)
  35. drone.move(x,y,z)
  36. travelx = travelx + x
  37. travely = travely + y
  38. travelz = travelz + z
  39. end
  40.  
  41. local function swing()
  42. for i=5,0,-1 do
  43. drone.swing(i)
  44. end
  45. sleep(0.2)
  46. end
  47.  
  48. local function swingHor()
  49. for i=1,5,1 do
  50. drone.swing(i)
  51. end
  52. sleep(0.2)
  53. end
  54.  
  55. local function suck(x)
  56. drone.suck(x)
  57. end
  58.  
  59. local function suckAll()
  60. for i=0,5,1 do
  61. suck(i)
  62. end
  63. end
  64.  
  65. local function placeD()
  66. drone.place(1)
  67. end
  68.  
  69. local function plant()
  70. drone.setStatusText("PLANTING")
  71. drone.select(1)
  72. move(-8,1,0)
  73. sleep(2)
  74. placeD()
  75.  
  76. move(-1,0,0)
  77. sleep(0.3)
  78. placeD()
  79.  
  80. move(0,0,-1)
  81. sleep(0.3)
  82. placeD()
  83.  
  84. move(1,0,0)
  85. sleep(0.3)
  86. placeD()
  87. returnHome()
  88. end
  89.  
  90. local function harvest()
  91. drone.setStatusText("CUTTING")
  92. moveLeft(20)
  93.  
  94. for i=1,4,1 do
  95. for i=1,8,1 do
  96. suckAll()
  97. swingHor()
  98. moveForward(1)
  99. end
  100. moveRight(1)
  101. for i=1,8,1 do
  102. suckAll()
  103. swingHor()
  104. moveBackward(1)
  105. end
  106. moveRight(1)
  107. end
  108.  
  109. returnHome()
  110. dropAll()
  111. sleep(2)
  112. end
  113.  
  114. local function resetP()
  115. travelx, travely, travelz = 0,0,0
  116. end
  117.  
  118. function returnHome()
  119. travelx = travelx * -1
  120. travely = travely * -1
  121. travelz = travelz * -1
  122. sleep(1)
  123. move(travelx,travely,travelz)
  124. sleep(2)
  125. resetP()
  126. end
  127.  
  128. local function moveLeft(a)
  129. sleep(0.5)
  130. if FARM_DIRECTION_EW ~= 0 then
  131. move(0, -a, 0)
  132. else
  133. move(-a, 0, 0)
  134. end
  135. sleep(0.5)
  136. end
  137.  
  138. local function moveRight(a)
  139. sleep(0.5)
  140. if FARM_DIRECTION_EW ~= 0 then
  141. move(0, a, 0)
  142. else
  143. move(a, 0, 0)
  144. end
  145. sleep(0.5)
  146. end
  147.  
  148. local function moveForward(a)
  149. sleep(0.5)
  150. move(a * FARM_DIRECTION_EW, a * FARM_DIRECTION_NS, 0)
  151. sleep(0.5)
  152. end
  153.  
  154. local function moveBackward(a)
  155. sleep(0.5)
  156. move(-a * FARM_DIRECTION_EW, -a * FARM_DIRECTION_NS, 0)
  157. sleep(0.5)
  158. end
  159.  
  160. local function setup()
  161. resetP()
  162. job = 0
  163. drone.setStatusText("CHECKING")
  164. drone.select(1)
  165. for i=1,40,1 do
  166. if not drone.compare(0, true) then
  167. break
  168. end
  169. moveForward(1)
  170. end
  171. returnHome()
  172. end
  173.  
  174. --start
  175. resetP()
  176. job = 0
  177. drone.setStatusText("ROM\nOK.v4.14.")
  178. sleep(1)
  179.  
  180. -- Main loop
  181.  
  182. setup()
  183. harvest()
  184. drone.setStatusText(tostring(job))
RAW Paste Data