SHARE
TWEET

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 move(x,y,z)
  17.   drone.move(x,y,z)
  18.   travelx = travelx + x
  19.   travely = travely + y
  20.   travelz = travelz + z
  21. end
  22.  
  23.  
  24. local function moveLeft(a)
  25.     sleep(0.5)
  26.     if FARM_DIRECTION_EW ~= 0 then
  27.         move(0, -a, 0)
  28.     else
  29.         move(-a, 0, 0)
  30.     end
  31.     sleep(0.5)
  32. end
  33.  
  34. local function moveRight(a)
  35.     sleep(0.5)
  36.     if FARM_DIRECTION_EW ~= 0 then
  37.         move(0, a, 0)
  38.     else
  39.         move(a, 0, 0)
  40.     end
  41.     sleep(0.5)
  42. end
  43.  
  44. local function moveForward(a)
  45.     sleep(0.5)
  46.     move(a * FARM_DIRECTION_EW, a * FARM_DIRECTION_NS, 0)
  47.     sleep(0.5)
  48. end
  49.  
  50. local function moveBackward(a)
  51.     sleep(0.5)
  52.     move(-a * FARM_DIRECTION_EW, -a * FARM_DIRECTION_NS, 0)
  53.     sleep(0.5)
  54. end
  55.  
  56. local function checkE()
  57.   local en = computer.energy()
  58.   return en
  59. end
  60.  
  61. local function drop()
  62.   drone.drop(2)
  63. end
  64.  
  65. local function dropAll()
  66.   for i=4,2,-1
  67.   do
  68.     drone.select(i)
  69.     drop()
  70.   end
  71.   drone.select(1)
  72. end
  73.  
  74. local function move(x,y,z)
  75.   drone.move(x,y,z)
  76.   travelx = travelx + x
  77.   travely = travely + y
  78.   travelz = travelz + z
  79. end
  80.  
  81. local function swing()
  82.   for i=5,0,-1 do
  83.     drone.swing(i)
  84.   end
  85.   sleep(0.2)
  86. end
  87.  
  88. local function swingHor()
  89.   for i=1,5,1 do
  90.     drone.swing(i)
  91.   end
  92.   sleep(0.2)
  93. end
  94.  
  95. local function suck(x)
  96.   drone.suck(x)
  97. end
  98.  
  99. local function suckAll()
  100.   for i=0,5,1 do
  101.     suck(i)
  102.   end
  103. end
  104.  
  105. local function placeD()
  106.   drone.place(1)
  107. end
  108.  
  109. local function plant()
  110.   drone.setStatusText("PLANTING")
  111.   drone.select(1)
  112.   move(-8,1,0)
  113.   sleep(2)
  114.   placeD()
  115.  
  116.   move(-1,0,0)
  117.   sleep(0.3)
  118.   placeD()
  119.  
  120.   move(0,0,-1)
  121.   sleep(0.3)
  122.   placeD()
  123.  
  124.   move(1,0,0)
  125.   sleep(0.3)
  126.   placeD()
  127.   returnHome()
  128. end
  129.  
  130. local function harvest()
  131.   drone.setStatusText("CUTTING")
  132.   moveLeft(20)
  133.  
  134.   for i=1,4,1 do
  135.       for i=1,8,1 do
  136.           suckAll()
  137.           swingHor()
  138.           moveForward(1)
  139.       end
  140.       moveRight(1)
  141.       for i=1,8,1 do
  142.           suckAll()
  143.           swingHor()
  144.           moveBackward(1)
  145.       end
  146.       moveRight(1)
  147.   end
  148.  
  149.   dropAll()
  150.   sleep(2)
  151. end
  152.  
  153. local function resetP()
  154.   travelx, travely, travelz = 0,0,0
  155. end
  156.  
  157. function returnHome()
  158.   travelx = travelx * -1
  159.   travely = travely * -1
  160.   travelz = travelz * -1
  161.   sleep(1)
  162.   move(travelx,travely,travelz)
  163.   sleep(2)
  164.   resetP()
  165. end
  166.  
  167.  
  168. local function setup()
  169.   resetP()
  170.   job = 0
  171.   drone.setStatusText("CHECKING")
  172.   drone.select(1)
  173.   for i=1,40,1 do
  174.       if not drone.compare(0, true) then
  175.           break
  176.       end
  177.       moveForward(1)
  178.   end
  179. end
  180.  
  181. --start
  182. resetP()
  183. job = 0
  184. drone.setStatusText("ROM\nOK.v4.14.")
  185. sleep(1)
  186.  
  187. -- Main loop
  188.  
  189. setup()
  190. harvest()
  191. returnHome()
  192. drone.setStatusText(tostring(job))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top