LOLROW

Untitled

Jul 14th, 2022 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.36 KB | None | 0 0
  1. --> AWT
  2.  
  3. rednet.open("left")
  4.  
  5. orientation = 0
  6.  
  7. function comeBack(xP, yP, zP) --> math time
  8.    
  9.     distanceX = 0
  10.     distanceY = 0
  11.     distanceZ = 0
  12.  
  13.     if (orientation > 0) then --> Figure out the orientation.
  14.         while (orientation > 0) do
  15.             orientation = orientation - 1
  16.             turtle.turnRight()
  17.         end
  18.     elseif (orientation < 0) then
  19.         while (orientation < 0) do
  20.             orientation = orientation + 1
  21.             turtle.turnLeft()
  22.         end
  23.     end
  24.     x, y, z = gps.locate(5)
  25.  
  26.     function cdbtap(x1, x2, y1, y2, z1, z2) --> Calculate distance between player and turtle. ACTUAL GPS RESPONSE PASS IN AS -> = X2, Y2, Z2!!!! REMEMBER
  27.         if (xP > x) then distanceX = xP - x else distanceX = x - xP end
  28.         if (yP > y) then distanceY = yP - y else distanceY = y - yP end
  29.         if (zP > z) then distanceZ = zP - z else distanceZ = z - zP end
  30.     end
  31.  
  32.     cdbtap(xP, x, yP, y, zP, z)
  33.  
  34.     original_distance_from_player_x = distanceX
  35.     original_distance_from_player_y = distanceY
  36.     original_distance_from_player_z = distanceZ
  37.  
  38.     print(distanceX) print(distanceY) print(distanceZ)
  39.  
  40.     while not (distanceX == 0 and distanceZ == 0) do --> While it hasn't reached your x and z
  41.         xx, yy, zz = gps.locate(1)
  42.  
  43.         if (xx == xP and zz == zP) then --> Double check to make sure ur not at the x and z. For some reason the while loop doesn't check it some times? idk why...
  44.             break
  45.         end
  46.  
  47.         if not (xx == xP and zz == zP) then --> If the turtle isn't at your coordinates then proceed to move it.
  48.             if (turtle.forward()) then
  49.                 newX, newY, newZ = gps.locate(5)
  50.    
  51.                 print(x, y, z)
  52.    
  53.                 print(newX, distanceX, newY, distanceY, newZ, distanceZ) --> debug line
  54.    
  55.                 if (xP > newX) then newX = xP - newX else newX = newX - xP end
  56.                 if (yP > newY) then newY = yP - newY else newY = newY - yP end
  57.                 if (zP > newZ) then newZ = zP - newZ else newZ = newZ - zP end
  58.    
  59.                 if (newX < distanceX or newY < distanceY or newZ < distanceZ) then
  60.  
  61.                     if not (distanceX == newX) then
  62.                         while not (newX == 0) do --> This makes the turtle MUCH MUCH MUCH faster at getting to you, because if the turtle moved in the right direction it loops in that direction.
  63.                             newX, newY, newZ = gps.locate()
  64.    
  65.                             if (turtle.forward()) then
  66.                                 newX, newY, newZ = gps.locate()
  67.    
  68.                                 if (xP > newX) then newX = xP - newX else newX = newX - xP end
  69.                                 if (yP > newY) then newY = yP - newY else newY = newY - yP end
  70.                                 if (zP > newZ) then newZ = zP - newZ else newZ = newZ - zP end
  71.    
  72.                             else
  73.                                 if not (turtle.up()) then for i = 0, 3, 1 do turtle.back() end turtle.up() end
  74.                             end
  75.                         end
  76.                     elseif not (distanceZ == newZ) then
  77.                         while not (newZ == 0) do
  78.                             newX, newY, newZ = gps.locate()
  79.    
  80.                             if (turtle.forward()) then
  81.                                 newX, newY, newZ = gps.locate()
  82.    
  83.                                 if (xP > newX) then newX = xP - newX else newX = newX - xP end
  84.                                 if (yP > newY) then newY = yP - newY else newY = newY - yP end
  85.                                 if (zP > newZ) then newZ = zP - newZ else newZ = newZ - zP end
  86.    
  87.                             else
  88.                                 if not (turtle.up()) then for i = 0, 3, 1 do turtle.back() end turtle.up() end
  89.                             end
  90.                         end
  91.                     end
  92.  
  93.                     print("A few step closer...")
  94.    
  95.                     distanceX = newX
  96.                     distanceY = newY
  97.                     distanceZ = newZ
  98.                 else
  99.                     turtle.back()
  100.                 end
  101.                 turtle.turnLeft() orientation = orientation - 1
  102.             else --> For some reason when it hits a wall it cant move but this fixed it.
  103.                 if not (turtle.up()) then for i = 0, 3, 1 do turtle.back() end turtle.up() end
  104.             end
  105.         end
  106.     end
  107.  
  108.     xxx, yyy, zzz = gps.locate(1)
  109.  
  110.     while not (yyy == yP + 1 or yyy == yP - 1 or yyy == yP) do --> If it reaches you're coordinates then it runs through this loop condition which checks if it's at your y coord and position the turtle correctly.
  111.         if (yyy > yP) then distanceBetweenYVals = yyy - yP else distanceBetweenYVals = yP - yyy end
  112.         if (turtle.up()) then
  113.             yyy = yyy + 1
  114.             if (yyy > yP) then distanceBetweenYVals2 = yyy - yP else distanceBetweenYVals2 = yP - yyy end
  115.  
  116.             if (distanceBetweenYVals2 > distanceBetweenYVals) then
  117.                 while not (yyy == yP + 1 or yyy == yP) do
  118.                     turtle.down()
  119.                 end
  120.             end
  121.         else
  122.             turtle.down()
  123.             yyy = yyy - 1
  124.             if (yyy > yP) then distanceBetweenYVals2 = yyy - yP else distanceBetweenYVals2 = yP - yyy end
  125.  
  126.             if (distanceBetweenYVals2 < distanceBetweenYVals) then
  127.                 while not (yyy == yP + 1 or yyy == yP) do
  128.                     turtle.down()
  129.                 end
  130.             end
  131.         end
  132.     end
  133.     print("Done")
  134. end
  135.  
  136. phoneID = 37 --> set phone id
  137.  
  138. while (true) do --> Listen for commands
  139.     id, message = rednet.receive("roombaNET-1")
  140.     print(id)
  141.     print(message)
  142.     if (id == 37) then
  143.         if (message == "comeback") then
  144.             id, message = rednet.receive("roombaNET-1")
  145.  
  146.             if (id == 37) then
  147.                 x = tonumber(message)
  148.  
  149.                 id, message = rednet.receive("roombaNET-1")
  150.                 if (id == 37) then
  151.                     y = tonumber(message)
  152.  
  153.                     id, message = rednet.receive("roombaNET-1")
  154.                     if (id == 37) then
  155.                         z = tonumber(message) --> z = tonumber(message)
  156.                         print("why no work fucker???")
  157.                         comeBack(x, y, z)
  158.                     end
  159.                 end
  160.             end
  161.         end
  162.     end
  163. end
  164.  
Add Comment
Please, Sign In to add comment