kreezxil

Turtlescript Goto Command

Jul 23rd, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. h = vector.new(gps.locate(5)) or vector.new(0,0,0)
  2. a = {...}
  3. k=tonumber
  4. d = vector.new(k(a[1]),k(a[2]),k(a[3]))
  5.  
  6. if a[4]=="r" then
  7. t = d
  8. else
  9. t=d-h
  10. end
  11.  
  12. m=math.abs
  13. f=m(t.x)+m(t.y)+m(t.z)
  14.  
  15. b=turtle
  16. e=b.forward
  17. n=b.turnRight
  18. o=b.turnLeft
  19. p=b.dig
  20. q=b.attack
  21. r=b.up
  22. s=b.down
  23. u=b.detect
  24.  
  25. if b.getFuelLevel() < f then
  26. for i=1,16 do
  27. b.select(i)
  28. b.refuel()
  29. end
  30. end
  31.  
  32. function w(l,h,d)
  33. for i=l,h do
  34. if u() then
  35. if not q() then
  36. p()
  37. end
  38. end
  39. d()
  40. end
  41. end
  42.  
  43. function v()
  44. n()
  45. n()
  46. end
  47.  
  48. if d.x>h.x then
  49. w(h.x,d.x,e)
  50. else
  51. v()
  52. w(d.x,h.x,e)
  53. v()
  54. end
  55.  
  56. if d.y>h.y then
  57. n()
  58. w(h.y,d.y,e)
  59. o()
  60. else
  61. o()
  62. w(d.y,h.y,e)
  63. n()
  64. end
  65.  
  66. if d.z>h.z then
  67. w(h.z,d.z,r)
  68. else
  69. w(d.z,h.z,s)
  70. end
Add Comment
Please, Sign In to add comment