Advertisement
kurruk

Turtle Build Code

May 11th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.41 KB | None | 0 0
  1. tArgs = {...}
  2. GUI = tArgs[1]
  3. directions = tArgs[1]
  4. times = tArgs[2]
  5. turns = 0
  6. turn = 0
  7. slot = 1
  8. x = 0
  9. y = 0
  10. z = 0
  11.  
  12. function forward()
  13.   if not turtle.forward() then
  14.     turtle.dig()
  15.     forward()
  16.   end
  17. end
  18.  
  19. function checkInv()
  20.   while true do
  21.     if slot <= 16 then
  22.       if turtle.getItemCount(slot) > 0 then
  23.         turtle.select(slot)
  24.         break
  25.       else
  26.         slot = slot + 1
  27.       end
  28.     else
  29.       print("out")
  30.       return false
  31.     end
  32.   end
  33. end
  34.  
  35. function right()
  36.   for i = 1, times - 1 do
  37.     turtle.place()
  38.     turtle.turnRight()
  39.     forward()
  40.     turtle.turnLeft()
  41.     print("Moves: "..turns)
  42.   end
  43.   turtle.place()
  44. end
  45.  
  46. function left()
  47.   for i = 1, times - 1 do
  48.     turtle.place()
  49.     turtle.turnLeft()
  50.     forward()
  51.     turtle.turnRight()
  52.     turns = turns + 1
  53.     print("Moves: "..turns)
  54.   end
  55.   turtle.place()
  56. end
  57.  
  58. function wall()
  59.   term.clear()
  60.   term.setCursorPos(1,1)
  61.   print("How high do you want it?")
  62.   high = read()
  63.   high = tonumber(high)
  64.   term.clear()
  65.   term.setCursorPos(1,1)
  66.   print("How long do you want it?")
  67.   times = read()
  68.   term.clear()
  69.   term.setCursorPos(1,1)
  70.   guiRight()
  71.   if direction == "right" then
  72.     while turn < high do
  73.       right()
  74.       turtle.up()
  75.       turn = turn + 1
  76.       if turn < high then
  77.         left()
  78.         turtle.up()
  79.         turn = turn + 1
  80.       end
  81.     end
  82.   elseif direction == "left" then
  83.     while turn < high do
  84.       left()
  85.       turtle.up()
  86.       turn = turn + 1
  87.       if turn < high then
  88.         right()
  89.         turtle.up()
  90.         turn = turn + 1
  91.       end
  92.     end
  93.   end
  94. end
  95.  
  96. function ground()
  97.   term.clear()
  98.   term.setCursorPos(1,1)
  99.   print("How deep do you want it?")
  100.   deep = read()
  101.   term.clear()
  102.   term.setCursorPos(1,1)
  103.   print("How wide do you want it?")
  104.   wide = read()
  105.   wide = tonumber(wide)
  106.   term.clear()
  107.   term.setCursorPos(1,1)
  108.   guiRight()
  109.   if direction == "right" then
  110.     while turn < wide do
  111.       for i = 1, deep - 1 do
  112.         if checkInv() then
  113.           break
  114.         end
  115.         if turtle.placeDown() == false then
  116.           turtle.digDown()
  117.           turtle.digUp()
  118.           turtle.placeDown()
  119.         end
  120.         forward()
  121.         y = y + 1
  122.       end
  123.       if checkInv() then
  124.             break
  125.           end
  126.       if turtle.placeDown() == false then
  127.         turtle.digDown()
  128.         turtle.digUp()
  129.         turtle.placeDown()
  130.       end
  131.       turtle.turnRight()
  132.       forward()
  133.       x = x + 1
  134.       turtle.turnRight()
  135.       turn = turn + 1
  136.       if turn < wide then
  137.         for i = 1, deep - 1 do
  138.           if checkInv() then
  139.             break
  140.           end
  141.           if turtle.placeDown() == false then
  142.             turtle.digDown()
  143.             turtle.digUp()
  144.             turtle.placeDown()
  145.           end
  146.           forward()
  147.           y = y - 1
  148.         end
  149.         if checkInv() then
  150.             break
  151.           end
  152.         if turtle.placeDown() == false then
  153.           turtle.digDown()
  154.           turtle.digUp()
  155.           turtle.placeDown()
  156.         end
  157.         turtle.turnLeft()
  158.         forward()
  159.         x = x + 1
  160.         turtle.turnLeft()
  161.         turn = turn + 1
  162.       end
  163.     end
  164.   elseif direction == "left" then
  165.     while turn < wide do
  166.       for i = 1, deep - 1 do
  167.         if checkInv() then
  168.           break
  169.         end
  170.         if turtle.placeDown() == false then
  171.           turtle.digDown()
  172.           turtle.digUp()
  173.           turtle.placeDown()
  174.         end
  175.         forward()
  176.         y = y + 1
  177.       end
  178.       if checkInv() then
  179.             break
  180.           end
  181.       if turtle.placeDown() == false then
  182.         turtle.digDown()
  183.         turtle.digUp()
  184.         turtle.placeDown()
  185.       end
  186.       turtle.turnLeft()
  187.       forward()
  188.       x = x + 1
  189.       turtle.turnLeft()
  190.       turn = turn + 1
  191.       if turn < wide then
  192.         for i = 1, deep - 1 do
  193.           if checkInv() then
  194.             break
  195.           end
  196.           if turtle.placeDown() == false then
  197.             turtle.digDown()
  198.             turtle.digUp()
  199.             turtle.placeDown()
  200.           end
  201.           forward()
  202.           y = y - 1
  203.         end
  204.         if checkInv() then
  205.             break
  206.           end
  207.         if turtle.placeDown() == false then
  208.           turtle.digDown()
  209.           turtle.digUp()
  210.           turtle.placeDown()
  211.         end
  212.         turtle.turnRight()
  213.         forward()
  214.         x = x + 1
  215.         turtle.turnRight()
  216.         turn = turn + 1
  217.       end
  218.     end
  219.   end
  220. end
  221.  
  222. function guiRight()
  223.   term.clear()
  224.   term.setCursorPos(1,1)
  225.   print("What direction do you want it?")
  226.   print(">Right<")
  227.   term.setCursorPos(10,2)
  228.   print("Left")
  229.   event, param = os.pullEvent("key")
  230.   key = keys.getName(param)
  231.     if key == "enter" then
  232.       direction = "right"
  233.     elseif key == "right" then
  234.       guiLeft()
  235.     else
  236.       guiRight()
  237.     end
  238. end
  239.  
  240. function guiLeft()
  241.   term.clear()
  242.   term.setCursorPos(1,1)
  243.   print("What direction do you want it?")
  244.   print("Right")
  245.   term.setCursorPos(10,2)
  246.   print(">Left<")
  247.   event, param = os.pullEvent("key")
  248.   key = keys.getName(param)
  249.     if key == "enter" then
  250.       direction = "left"
  251.     elseif key == "left" then
  252.       guiRight()
  253.     else
  254.       guiLeft()
  255.     end
  256. end
  257.  
  258. function guiWall()
  259.   term.clear()
  260.   term.setCursorPos(1,1)
  261.   print("Welcome, How may I help you.")
  262.   term.setCursorPos(4,3)
  263.   print(">Wall<")
  264.   term.setCursorPos(14,3)
  265.   print("Floor")
  266.   term.setCursorPos(4,5)
  267.   print("Stair")
  268.   term.setCursorPos(14,5)
  269.   print("")
  270.   event, param = os.pullEvent("key")
  271.   key = keys.getName(param)
  272.     if key == "enter" then
  273.       wall()
  274.     elseif key == "right" then
  275.       guiFloor()
  276.     elseif key == "down" then
  277.       guiStair()
  278.     else
  279.       guiWall()
  280.     end
  281. end
  282.  
  283. function guiStair()
  284.   term.clear()
  285.   term.setCursorPos(1,1)
  286.   print("Welcome, How may I help you.")
  287.   term.setCursorPos(4,3)
  288.   print("Wall")
  289.   term.setCursorPos(14,3)
  290.   print("Floor")
  291.   term.setCursorPos(4,5)
  292.   print(">Stair<")
  293.   term.setCursorPos(14,5)
  294.   print("")
  295.   event, param = os.pullEvent("key")
  296.   key = keys.getName(param)
  297.     if key == "enter" then
  298.       wall()
  299.     elseif ey == "right" then
  300.       guiFloor()
  301.     elseif key == "up" then
  302.       guiWall()
  303.     else
  304.       guiStair()
  305.     end
  306. end
  307.  
  308. function guiFloor()
  309.   term.clear()
  310.   term.setCursorPos(1,1)
  311.   print("Welcome, How may I help you.")
  312.   term.setCursorPos(4,3)
  313.   print("Wall")
  314.   term.setCursorPos(14,3)
  315.   print(">Floor<")
  316.   term.setCursorPos(4,5)
  317.   print("Stair")
  318.   term.setCursorPos(14,5)
  319.   print("")
  320.   event, param = os.pullEvent("key")
  321.   key = keys.getName(param)
  322.     if key == "enter" then
  323.       ground()
  324.     elseif key == "left" then
  325.       guiWall()
  326.     elseif key == "down" then
  327.       guiStair()
  328.     else
  329.       guiFloor()
  330.     end
  331. end
  332.  
  333. function home()
  334. print("Out of resources")
  335. end
  336.  
  337. --Main running code
  338. if GUI == "gui" then
  339.   guiWall()
  340. elseif directions == "right" then
  341.   right()
  342. elseif directions == "left" then
  343.   left()
  344. else
  345.   print("Usage: roof direction times")
  346. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement