Advertisement
Vorakh

Direwolf20 goto Turtle Script

Jul 29th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. -- Direwolf20 goto Turtle Script
  2. -- Original Paste http://pastebin.com/eynvT9Rv
  3. -- Used in Season 3 - Episode 25 - SMP Direwolf20's Minecraft Server Play
  4. -- http://www.youtube.com/watch?v=DhE5ddWI_eU
  5. -- Min 26:10
  6.  
  7. local tArgs = {...}
  8. local x = tonumber(tArgs[1])
  9. local y = tonumber(tArgs[2])
  10. local z = tonumber(tArgs[3])
  11. local curx, cury, curz, dir
  12.  
  13. function getPos()
  14.    return gps.locate(3)
  15. end
  16.  
  17. function getDir()
  18.    local dir, x, y, z
  19.    x, y, z = getPos()
  20.    --print("Old: "..x..","..y..","..z)
  21.    while not turtle.forward() do
  22.       while not turtle.up() do
  23.             turtle.digUp()
  24.       end
  25.    end
  26.    nx, ny, nz = getPos()
  27.    --print ("New: "..nx..","..ny..","..nz)
  28.    if (x == nx) then
  29.       if (nz > z) then
  30.          dir = 2
  31.       else
  32.          dir = 0
  33.       end
  34.    else
  35.       if (nx > x) then
  36.          dir = 3
  37.       else
  38.          dir = 1
  39.       end
  40.    end
  41.    return dir
  42. end
  43.  
  44.  
  45. function setDir(toDir)
  46.    while toDir ~= dir do
  47.       turtle.turnLeft()
  48.       if dir == 3 then
  49.          dir=0
  50.       else
  51.          dir=dir+1
  52.       end
  53.    end  
  54. end
  55.  
  56. function moveX()
  57.    distx = x - curx
  58.    --print(distx)
  59.    if (x > curx) then
  60.       setDir(3)
  61.    else
  62.       setDir(1)
  63.    end
  64.    distx = math.abs(distx)
  65.    --print(distx)
  66.  
  67.    for i = 1, distx do
  68.       while not turtle.forward() do
  69.          while not turtle.up() do
  70.             turtle.digUp()
  71.          end
  72.       end
  73.    end
  74. end
  75.  
  76. function moveZ()
  77.    distz = z - curz
  78.    if (z < curz) then
  79.       setDir(0)
  80.    else
  81.       setDir(2)
  82.    end
  83.    distz = math.abs(distz)
  84.    --print(distz)
  85.  
  86.    for i = 1, distz do
  87.       while not turtle.forward() do
  88.          while not turtle.up() do
  89.             turtle.digUp()
  90.          end
  91.       end
  92.    end
  93. end
  94.  
  95. function moveY()
  96.    disty = y - cury
  97.    disty = math.abs(disty)
  98.    if (y < cury) then
  99.       for i = 1, disty do
  100.          while not turtle.down() do
  101.             turtle.digDown()
  102.          end
  103.       end
  104.    else
  105.       for i = 1, disty do
  106.          while not turtle.up() do
  107.             turtle.digUp()
  108.           end
  109.        end
  110.    end
  111.    
  112. end
  113.  
  114. --=====================--
  115. if not x or not y or not z then
  116.    print("Must supply X Y Z")
  117.    exit()
  118. end
  119.  
  120. rednet.open("right")
  121. --print (x..","..y..","..z)
  122. dir = getDir()
  123. curx, cury, curz = getPos()
  124. distx = x - curx
  125. disty = y - cury
  126. distz = z - curz
  127. --print ("Current: "..curx..","..cury..","..curz)
  128. --print ("Distance: "..distx..","..disty..","..distz)
  129.  
  130. moveX()
  131. curx, cury, curz = getPos()
  132. moveZ()
  133. curx, cury, curz = getPos()
  134. moveY()
  135. curx, cury, curz = getPos()
  136. print ("Current: "..curx..","..cury..","..curz)
  137. rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement