AnonymusHochgenuss

goto

Jul 15th, 2021 (edited)
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.29 KB | None | 0 0
  1. local tArgs = { ... }
  2. x1 = tonumber(tArgs[1])
  3. y1 = tonumber(tArgs[2])
  4. z1 = tonumber(tArgs[3])
  5. fxyz = tArgs[4]
  6. print("target: "..x1..", "..y1..", "..z1)
  7. ---- functions ----
  8.  
  9. function locate()
  10.  x, y, z = gps.locate()
  11. end
  12.  
  13. function locate1()
  14.  locate()
  15.  x2=tonumber(x)
  16.  y2=tonumber(y)
  17.  z2=tonumber(z)
  18.  e=0
  19.  while turtle.detect() do
  20.   turtle.turnRight()
  21.   e=e+1
  22.   if e > 3 then
  23.    print("all sides blocked")
  24.    return
  25.   end
  26.  end
  27.  while not turtle.forward() do
  28.   sleep(1)
  29.  end
  30.  locate()
  31.  if z < z2 then
  32.   f="north"
  33.  elseif x > x2 then
  34.   f="east"
  35.  elseif z > z2 then
  36.   f="south"
  37.  elseif x < x2 then
  38.   f="west"
  39.  end
  40. end
  41.  
  42.  
  43. function facing(f1)
  44.  -- locate1()
  45.  print("facing actually to: "..f)
  46.  print("turning facing to "..f1)
  47.  if f1 == "north" then
  48.   if f == "north" then
  49.   elseif f == "east" then
  50.    turtle.turnRight()
  51.    turtle.turnRight()
  52.    turtle.turnRight()
  53.   elseif f == "south" then
  54.    turtle.turnRight()
  55.    turtle.turnRight()
  56.   elseif f == "west" then
  57.    turtle.turnRight()
  58.   end
  59.   f="north"
  60.  end
  61.  if f1 == "east" then
  62.   if f == "north" then
  63.    turtle.turnRight()
  64.   elseif f == "east" then
  65.   elseif f == "south" then
  66.    turtle.turnRight()
  67.    turtle.turnRight()
  68.    turtle.turnRight()
  69.   elseif f == "west" then
  70.    turtle.turnRight()
  71.    turtle.turnRight()
  72.   end
  73.   f="east"
  74.  end
  75.  if f1 == "south" then
  76.   if f == "north" then
  77.    turtle.turnRight()
  78.    turtle.turnRight()
  79.   elseif f == "east" then
  80.    turtle.turnRight()
  81.   elseif f == "south" then
  82.   elseif f == "west" then
  83.    turtle.turnRight()
  84.    turtle.turnRight()
  85.    turtle.turnRight()
  86.   end
  87.   f="south"
  88.  end
  89.  if f1 == "west" then
  90.   if f == "north" then
  91.    turtle.turnRight()
  92.    turtle.turnRight()
  93.    turtle.turnRight()
  94.   elseif f == "east" then
  95.    turtle.turnRight()
  96.    turtle.turnRight()
  97.   elseif f == "south" then
  98.    turtle.turnRight()
  99.   elseif f == "west" then
  100.   end
  101.   f="west"
  102.  end
  103. end
  104.  
  105. ---------------------------
  106.  
  107. x=false
  108. y=false
  109. z=false
  110. locate()
  111. if x then
  112.  print("position: "..x..", "..y..", "..z)
  113.  x2=tonumber(x)
  114.  y2=tonumber(y)
  115.  z2=tonumber(z)
  116.  e=0
  117.  while turtle.detect() do
  118.   turtle.turnRight()
  119.   e=e+1
  120.   if e > 3 then
  121.    print("all sides blocked. couldn't determine")
  122.    return
  123.   end
  124.  end
  125.  while not turtle.forward() do
  126.   sleep(1)
  127.  end
  128.  locate()
  129.  if z < z2 then
  130.   f="north"
  131.  elseif x > x2 then
  132.   f="east"
  133.  elseif z > z2 then
  134.   f="south"
  135.  elseif x < x2 then
  136.   f="west"
  137.  end
  138.  while y < 100 do
  139.   while not turtle.up() do
  140.    sleep(1)
  141.   end
  142.   y=y+1
  143.  end
  144.  locate()
  145.  if x1 < x then
  146.   f1="west"
  147.   facing(f1)
  148.   while x > x1 do
  149.    while not turtle.forward() do
  150.     sleep(0.5)
  151.    end
  152.    x=x-1
  153.   end
  154.  elseif x1 > x then
  155.   f1="east"
  156.   facing(f1)
  157.   while x < x1 do
  158.    while not turtle.forward() do
  159.     sleep(0.5)
  160.    end
  161.    x=x+1
  162.   end
  163.  end
  164.  if z1 > z then
  165.   f1="south"
  166.   facing(f1)
  167.   while z < z1 do
  168.    while not turtle.forward() do
  169.     sleep(0.5)
  170.    end
  171.    z=z+1
  172.   end
  173.  elseif z1 < z then
  174.   f1="north"
  175.   facing(f1)
  176.   while z > z1 do
  177.    while not turtle.forward() do
  178.     sleep(0.5)
  179.    end
  180.    z=z-1
  181.   end
  182.  end
  183.  locate()
  184.  print("position: "..x..", "..y..", "..z)
  185.  while y > y1 do
  186.   while not turtle.down() do
  187.    sleep(0.5)
  188.   end
  189.   y=y-1
  190.  end
  191.  if not fxyz then
  192.  else
  193.   facing(fxyz)
  194.  end
  195. else
  196.  print("location not found")
  197. end
Add Comment
Please, Sign In to add comment