Advertisement
ZzexMC

t

Apr 23rd, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. x = 0
  2. y = 0
  3. z = 0
  4. dir = 0
  5.  
  6. -- check fuel
  7. function fuel()
  8.     if turtle.getFuelLevel() <= 100 then
  9.         turtle.select(16)
  10.         turtle.refuel(1)
  11.         print("Refueled. Fuel level is :".. turtle.getFuelLevel())
  12.     end
  13. end
  14.  
  15. -- up
  16. function up()
  17.     fuel()
  18.     if turtle.up() then
  19.         return true
  20.     end
  21.     return false
  22. end
  23.  
  24. -- down
  25. function dn()
  26.     fuel()
  27.     if turtle.down() then
  28.         return true
  29.     end
  30.     return false
  31. end
  32.  
  33. -- turnLeft
  34. function lt()
  35.     if turtle.turnLeft() then
  36.         dir = dir - 1
  37.         if dir < 0 then
  38.             dir = 3
  39.         end    
  40.         return true
  41.     end
  42.     return false
  43. end
  44.  
  45. -- turnRight
  46. function rt()
  47.     if turtle.turnRight() then
  48.         dir = dir + 1
  49.         if dir > 3 then
  50.             dir = 0
  51.         end
  52.         return true
  53.     end
  54.     return false
  55. end
  56.  
  57. -- forward
  58. function fd()
  59.     fuel()
  60.     if turtle.forward() then
  61.         changePos("fd")
  62.         return true
  63.     end
  64.     return false
  65. end
  66.  
  67. -- back
  68. function bk()
  69.     fuel()
  70.     if turtle.back() then
  71.         changePos("bk")
  72.         return true
  73.     end
  74.     return false
  75. end
  76.  
  77. -- get location by gps
  78. function gpsUpdate()
  79.     x, y, z = gps.locate(5)
  80.     if x == nil then
  81.         return false
  82.     end
  83.     return true
  84. end
  85.  
  86. -- direction
  87. function checkDir()
  88.     turtle.forward()
  89.     turtle.forward()
  90.     cx, cy, cz = gps.locate(1)
  91.     if (x - cx) == 2 then
  92.         print("W")
  93.         dir = 3
  94.     end
  95.  
  96.     if (z - cz) == 2 then
  97.         print("N")
  98.         dir = 0
  99.     end
  100.  
  101.     if (x - cx) == -2 then
  102.         print("E")
  103.         dir = 1
  104.     end
  105.  
  106.     if (z - cz) == -2 then
  107.         print("S")
  108.         dir = 2
  109.     end
  110.  
  111.     turtle.back()
  112.     turtle.back()
  113. end
  114.  
  115. function getDir()
  116.     print(dir)
  117. end
  118.  
  119. -- change pos
  120. function changePos(command)
  121.     if command == "fd" then
  122.         if dir == 0 then
  123.             z = z - 1
  124.         end
  125.         if dir == 1 then
  126.             x = x + 1
  127.         end
  128.         if dir == 2 then
  129.             z = z + 1
  130.         end
  131.         if dir == 3 then
  132.             x = x - 1
  133.         end
  134.     end
  135.  
  136.     if command == "bk" then
  137.         if dir == 0 then
  138.             z = z + 1
  139.         end
  140.         if dir == 1 then
  141.             x = x - 1
  142.         end
  143.         if dir == 2 then
  144.             z = z - 1
  145.         end
  146.         if dir == 3 then
  147.             x = x + 1
  148.         end
  149.     end
  150. end
  151.  
  152. -- get positions
  153. function getPos()
  154.     print(x..","..y..","..z)
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement