the_lad

Turtle Bomber

Apr 15th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. args = {...}
  2. d = 0
  3. distance = args[1]
  4. tonumber(distance)
  5. tx = args[1]
  6. ty = args[2]
  7. tz = args[3]
  8. hx,hy,hz = gps.locate()
  9. x = hx
  10. y = hy
  11. z = hz
  12. print("home:",hx,hy,hz)
  13. print("target:",tx,ty,tz)
  14. planted = false
  15. function Refuel()
  16.     d2 = (2*math.abs(tx-hx)+2*math.abs(tz-hz)+math.abs(120-hy)+math.abs(120-ty))
  17.     n=math.ceil(d2/80)
  18.     print(n)
  19.     turtle.select(1)
  20.     turtle.refuel(n)
  21. end
  22.  
  23. function Det()
  24.  print(table.getn(args))
  25.  i = table.getn(args)
  26.  if i == 0 or i == nil then
  27.  printError("Nothing Defined, Use distance or coordinates")
  28.  elseif i == 1 then
  29.  print("Running In Distance Mode")
  30.  Run()
  31.  elseif i == 3 then
  32.  print("Running In GPS Mode")
  33.  GPSCal()
  34.  elseif i >= 3 then
  35.  printError("Too many Arguments")
  36.  end
  37. end
  38.  
  39. function GPSCal()
  40.     Refuel()
  41.     --go up to lvl 120
  42.     while y < 120 do
  43.     turtle.up()
  44.     y = y+1
  45.     end
  46.     --calibrate x and y
  47.     ix,iy,iz = gps.locate()
  48.     turtle.forward()
  49.     x,y,z = gps.locate()
  50.     if x - ix == 1 then
  51.     RunGPS()
  52.     elseif x - ix == -1 then
  53.     turtle.turnRight()
  54.     turtle.turnRight()
  55.     RunGPS()
  56.     elseif z - iz == 1 then
  57.     turtle.turnLeft()
  58.     RunGPS()
  59.     elseif z - iz == -1 then
  60.     turtle.turnRight()
  61.     RunGPS()
  62.     else
  63.     printError("GPS ERROR")
  64.     end
  65. end
  66.  
  67. function RunGPS()
  68.     x,y,z = gps.locate()
  69.     --go x
  70.     if x < tonumber(tx) then
  71.     while x<tonumber(tx) do
  72.     if turtle.getFuelLevel() == 0 then
  73.     Refuel()
  74.     end
  75.     turtle.forward()
  76.     x=x+1
  77.     end
  78.     elseif x > tonumber(tx) then
  79.     while x>tonumber(tx) do
  80.     if turtle.getFuelLevel() == 0 then
  81.     Refuel()
  82.     end
  83.     turtle.back()
  84.     x=x-1
  85.     end
  86.     end
  87.     --go z
  88.     if z<tonumber(tz) then
  89.     turtle.turnRight()
  90.     while z<tonumber(tz) do
  91.     if turtle.getFuelLevel() == 0 then
  92.     Refuel()
  93.     end
  94.     turtle.forward()
  95.     z=z+1
  96.     end
  97.     elseif z>tonumber(tz) then
  98.     turtle.turnLeft()
  99.     while z>tonumber(tz) do
  100.     if turtle.getFuelLevel() == 0 then
  101.     Refuel()
  102.     end
  103.     turtle.forward()
  104.     z=z-1
  105.     end
  106.     end
  107.     --DESCEND
  108.     while y>tonumber(ty) or turtle.detectDown() == false do
  109.     if turtle.getFuelLevel() == 0 then
  110.     Refuel()
  111.     end
  112.     turtle.down()
  113.     y=y-1
  114.     if turtle.detectDown() == true then
  115.     if planted == false then
  116.     Plant()
  117.     else
  118.     print("home")
  119.     end
  120.     end
  121.     end
  122. end
  123.  
  124. function Run()
  125. turtle.refuel(math.ceil(tx/80))
  126. redstone.setOutput("right", false)
  127. while tonumber(d) < tonumber(distance) do
  128. if turtle.detect() == false then
  129. turtle.forward()
  130. d = d+1
  131. elseif turtle.detect() == true then
  132. Plant()
  133. elseif d == distance then
  134. Plant()
  135. end
  136. end
  137. end
  138.  
  139. function Plant()
  140. turtle.back()
  141. turtle.select(2)
  142. turtle.place()
  143. turtle.back()
  144. turtle.back()
  145. turtle.select(3)
  146. turtle.place()
  147. turtle.turnLeft()
  148. redstone.setOutput("right", true)
  149. planted = true
  150. tx = hx
  151. ty = hy
  152. tz = hz
  153. GPSCal()
  154. end
  155. Det()
Add Comment
Please, Sign In to add comment