Dustrider

Direwolf20 goto script

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