Advertisement
Guest User

Turtle tanker

a guest
Mar 31st, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.47 KB | None | 0 0
  1. print("Current x coordinate:")
  2. Coordx = read()
  3.  
  4. print("Current y coordinate:")
  5. Coordy = read()
  6.  
  7. print("Current z coordinate:")
  8. Coordz = read()
  9.  
  10. print("Currently Faceing(0,1,2,3):")
  11. rotation = read()
  12.  
  13. startX = Coordx
  14.  
  15. startY = Coordy
  16.  
  17. startZ = Coordz
  18.  
  19.  
  20. function turnLeft()
  21.    
  22.     turtle.turnLeft()
  23.    
  24.     rotation = rotation - 1
  25.    
  26.     if rotation == -1 then
  27.    
  28.         rotation = 3
  29.        
  30.     end
  31.    
  32. end
  33.  
  34. function turnRight()
  35.    
  36.     turtle.turnRight()
  37.    
  38.     rotation = rotation + 1
  39.    
  40.     if rotation == 4 then
  41.        
  42.         rotation = 0
  43.        
  44.     end
  45.    
  46. end
  47.  
  48. function dig()
  49.    
  50.     repeat
  51.  
  52.         x, y = turtle.inspect()
  53.  
  54.         if x == true then
  55.  
  56.             turtle.dig()
  57.    
  58.         end
  59.  
  60.         sleep(1)
  61.  
  62.     until x == false
  63.    
  64. end
  65.  
  66. function digUp()
  67.    
  68.     repeat
  69.  
  70.         x, y = turtle.inspectUp()
  71.  
  72.         if x == true then
  73.  
  74.             turtle.digUp()
  75.    
  76.         end
  77.  
  78.         sleep(1)
  79.  
  80.     until x == false
  81.    
  82. end
  83.  
  84. function digDown()
  85.    
  86.     repeat
  87.  
  88.         x, y = turtle.inspectDown()
  89.  
  90.         if x == true then
  91.  
  92.             turtle.digDown()
  93.    
  94.         end
  95.  
  96.         sleep(1)
  97.  
  98.     until x == false
  99.    
  100. end
  101.  
  102. function move(toMove)
  103.    
  104.     moved = 0
  105.    
  106.     while moved ~= toMove do
  107.    
  108.         repeat
  109.        
  110.             dig()
  111.             x = turtle.forward()
  112.            
  113.         until x == true
  114.        
  115.         if rotation == 0 then
  116.            
  117.             Coordz = Coordz + 1
  118.            
  119.         elseif rotation == 1 then
  120.        
  121.             Coordx = Coordx - 1
  122.            
  123.         elseif rotation == 2 then
  124.        
  125.             Coordz = Coordz - 1
  126.            
  127.         elseif rotation == 3 then
  128.        
  129.             Coordx = Coordx + 1
  130.            
  131.         end
  132.            
  133.         moved = moved + 1
  134.        
  135.     end
  136.    
  137. end
  138.  
  139. function moveDown(toMove)
  140.    
  141.     moved = 0
  142.    
  143.     while moved ~= toMove do
  144.    
  145.         repeat
  146.        
  147.             digDown()
  148.             x = turtle.down()
  149.            
  150.         until x == true
  151.        
  152.         Coordy = Coordy - 1
  153.         moved = moved + 1
  154.        
  155.     end
  156.    
  157. end
  158.  
  159. function moveUp(toMove)
  160.    
  161.     moved = 0
  162.    
  163.     while moved ~= toMove do
  164.    
  165.         repeat
  166.        
  167.             digUp()
  168.             x = turtle.up()
  169.            
  170.         until x == true
  171.        
  172.        
  173.         Coordy = Coordy + 1
  174.         moved = moved + 1
  175.        
  176.     end
  177.    
  178. end
  179.  
  180. function GoTo(x, y, z)
  181.  
  182.     if y - Coordy > 0 then
  183.    
  184.         moveUp(y - Coordy)
  185.        
  186.     else
  187.    
  188.         moveDown(-(y - Coordy))
  189.        
  190.     end
  191.    
  192.     if x - Coordx > 0 then
  193.        
  194.         while rotation ~= 3 do
  195.        
  196.             turnRight()
  197.            
  198.         end
  199.        
  200.         move(x - Coordx)
  201.        
  202.     else
  203.    
  204.         while rotation ~= 1 do
  205.            
  206.             turnRight()
  207.            
  208.         end
  209.            
  210.            
  211.         move(-(x - Coordx))
  212.        
  213.     end
  214.  
  215.  
  216.     if z - Coordz > 0 then
  217.        
  218.         while rotation ~= 0 do
  219.        
  220.             turnRight()
  221.            
  222.         end
  223.        
  224.         move(z - Coordz)
  225.        
  226.     else
  227.        
  228.         while rotation ~= 2 do
  229.            
  230.             turnRight()
  231.            
  232.         end
  233.        
  234.         move(-(z - Coordz))
  235.        
  236.     end
  237.    
  238. end
  239.  
  240. print("Go to x:")
  241. x = read()
  242.  
  243. print("Go to y:")
  244. y = read()
  245.  
  246. print("Go to z:")
  247. z = read()
  248.  
  249.  
  250. repeat
  251.  
  252. GoTo(x, y, z)
  253.  
  254. turtle.select(1)
  255. turtle.placeDown()
  256.  
  257. sleep(15)
  258.  
  259. digDown()
  260.  
  261. GoTo(startX, startY, startZ)
  262.  
  263. turtle.select(1)
  264. turtle.placeDown()
  265.  
  266. sleep(15)
  267.  
  268. digDown()
  269.  
  270. until 1 == 0
  271.  
  272. GoTo(oCoordx, oCoordy, oCoordz)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement