Advertisement
krzys_h

Idź Do v1.0

Aug 20th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local x,y,z,dir
  2. function loc(txt)
  3.  x,y,z = gps.locate(2, false)
  4.  if x == nil then
  5.   print("Blad GPS")
  6.  else
  7.   if txt then
  8.    print("Pos: " .. x .. ", " .. y .. ", " .. z)
  9.   end
  10.  end
  11. end
  12.  
  13. function turn(ctdir)
  14.  while dir ~= ctdir do
  15.   print(dir)
  16.   turtle.turnRight()
  17.   dir = dir + 1
  18.   if dir == 4 then dir = 0 end
  19.  end
  20. end
  21.  
  22. write("Cur: ")
  23. loc(true)
  24.  
  25. write("Cur: Dir: ")
  26. sx = x
  27. sy = y
  28. sz = z
  29. place = true
  30. if turtle.forward() then
  31.  place = false
  32. else
  33.  turtle.dig()
  34.  turtle.forward()
  35. end
  36. loc(false)
  37. if z == (sz+1) then dir = 0 end
  38. if x == (sx-1) then dir = 1 end
  39. if z == (sz-1) then dir = 2 end
  40. if x == (sx+1) then dir = 3 end
  41. turtle.back()
  42. if place then
  43.  turtle.place()
  44. end
  45. print(dir)
  46.  
  47.  
  48. write("Tgt: Pos: ")
  49. local tArgs = { ... }
  50. tx = tonumber(tArgs[1])
  51. ty = tonumber(tArgs[2])
  52. tz = tonumber(tArgs[3])
  53. tdir = dir
  54. print(tx .. ", " .. ty .. ", " .. tz)
  55. print(" ")
  56.  
  57. write("Tgt: Dir: ")
  58. print(tdir)
  59.  
  60. while y ~= ty do
  61.  if y<ty then
  62.   if turtle.up() then
  63.   else
  64.    turtle.digUp()
  65.    turtle.up()
  66.    turtle.placeDown()
  67.   end
  68.  end
  69.  if y>ty then
  70.   if turtle.down() then
  71.   else
  72.    turtle.digDown()
  73.    turtle.down()
  74.    turtle.placeUp()
  75.   end
  76.  end
  77.  loc(true)
  78. end
  79.  
  80. if x>tx then ctdir = 1 end
  81. if x<tx then ctdir = 3 end
  82. turn(ctdir)
  83. print(ctdir)
  84.  
  85. while x ~= tx do
  86.  if turtle.forward() then
  87.  else
  88.   turtle.dig()
  89.   turtle.forward()
  90.   turtle.turnRight()
  91.   turtle.turnRight()
  92.   turtle.place()
  93.   turtle.turnRight()
  94.   turtle.turnRight()
  95.  end
  96.  loc(true)
  97. end
  98.  
  99. if z>tz then ctdir = 2 end
  100. if z<tz then ctdir = 0 end
  101. turn(ctdir)
  102. print(ctdir)
  103.  
  104. while z ~= tz do
  105.  if turtle.forward() then
  106.  else
  107.   turtle.dig()
  108.   turtle.forward()
  109.   turtle.turnRight()
  110.   turtle.turnRight()
  111.   turtle.place()
  112.   turtle.turnRight()
  113.   turtle.turnRight()
  114.  end
  115.  loc(true)
  116. end
  117.  
  118. turn(tdir)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement