Advertisement
ThaWade

ComputerCraft Turtle Program: Ultra Stairs v.2

Jan 21st, 2016
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.47 KB | None | 0 0
  1. --[[ComputerCraft Turtle Program: Ultra Stairs v.2
  2.     pastebin get WTXCeWQM
  3.  
  4. .....................EDIT LOG.......................
  5. EDITED: 14, Nov. 2014. Reason: Added a return to start position function called back().
  6. EDITED: 31, March 2015. Reason: Fixed so gravel/sand doesn't break the turtle's groove. Also changed name to match
  7. the other secondary program.
  8. EDITED: 31, March 2015. cont. Also added the cleanup program functionality to this code.
  9. digs out and places stairs
  10. EDITED: 18, September 2015. Reason: Added the ability to make stairs up or down. Also, fixed some things in the EDIT LOG.
  11. pastebin for my orginal stairs program: pastebin get t6kdBeq0
  12. EDITED: 21, Jan. 2016. Reason: Added the ability to make stairs in mid air without the stairs placing upside down. See airStairsUp, airStairsDown for the code.
  13. ]]
  14.  
  15. fuelType = {
  16. coal = 80
  17. }
  18.  
  19. local block = 1
  20. local stairs = 9
  21. local fuelUsed = 0
  22.  
  23. local tArgs = { ... }
  24. if #tArgs ~= 1 then
  25.     print( "Usage: Stairs <amount>" )
  26.     return
  27. end
  28.  
  29. local amount = tonumber( tArgs[1] )
  30.  
  31. function aboutFace()
  32.     turtle.turnRight()
  33.     turtle.turnRight()
  34. end
  35.  
  36. function placeStair()--place Stair
  37.     turtle.select(stairs)
  38.     aboutFace()
  39.     turtle.place()
  40.     aboutFace()
  41. end
  42.  
  43. function digOut()--moves to position next stair
  44.     turtle.select(block)
  45.     turtle.digDown()
  46.     while not
  47.     turtle.forward() do
  48.     turtle.dig()
  49.     end
  50.     turtle.digDown()
  51.     turtle.dig()
  52.     turtle.down()
  53.     fuelUsed = fuelUsed + 1
  54.     print(fuelUsed)
  55.     placeStair()
  56.     turtle.dig()
  57. end
  58. ---------------------------------STAIRS DOWN START---------------------------------------
  59. function stairsDown()
  60. --print("distance Down?")
  61. --amount = io.read()
  62. for i = 1, amount do
  63.     digOut()
  64. end
  65.  
  66. turtle.forward()
  67.  
  68. function back()
  69.     turtle.up()
  70.     fuelUsed = fuelUsed + 1
  71.     print(fuelUsed)
  72.     turtle.digUp()
  73.     turtle.back()
  74.     fuelUsed = fuelUsed + 1
  75.     print(fuelUsed)
  76. end
  77.  
  78. for z = 1, amount + 1 do
  79.     back()
  80. end
  81. end
  82. ---------------------------------STAIRS DOWN END---------------------------------------
  83. ---------------------------------STAIRS UP START---------------------------------------
  84. function digOutUp()
  85.     turtle.digUp()
  86.     turtle.dig()
  87.     turtle.forward()
  88.     fuelUsed = fuelUsed + 1
  89.     print(fuelUsed)
  90.     turtle.dig()
  91.     turtle.digUp()
  92.     turtle.digDown()
  93.     turtle.select(stairs)
  94.     turtle.placeDown()
  95.     turtle.up()
  96.     fuelUsed = fuelUsed + 1
  97.     print(fuelUsed)
  98. end
  99.  
  100. function back()
  101.     turtle.digUp()
  102.     turtle.down()
  103.     fuelUsed = fuelUsed + 1
  104.     print(fuelUsed)
  105.     turtle.back()
  106. end
  107.  
  108. function stairsUp()
  109.     for i = 1, amount do
  110.         digOutUp()
  111.     end
  112.     turtle.back()
  113.     fuelUsed = fuelUsed + 1
  114.     print(fuelUsed)
  115.     turtle.down()
  116.     fuelUsed = fuelUsed + 1
  117.     print(fuelUsed)
  118.     turtle.back()
  119.     fuelUsed = fuelUsed + 1
  120.     print(fuelUsed)
  121.     for i = 1, amount - 1 do
  122.         back()
  123.     end
  124. end
  125. ---------------------------------STAIRS UP END---------------------------------------
  126. function airBackUp()
  127.     turtle.back()
  128.     fuelUsed = fuelUsed + 1
  129.     print(fuelUsed)
  130.     turtle.down()
  131.     fuelUsed = fuelUsed + 1
  132.     print(fuelUsed)
  133. end
  134. ---------------------------------AIR STAIRS UP START---------------------------------------
  135. local t = turtle
  136.  
  137. function airStairsUp()
  138.     for i = 1, amount do
  139.         t.select(block)
  140.         t.place()
  141.         t.turnLeft()
  142.         t.place()
  143.         t.turnRight()
  144.         t.turnRight()
  145.         t.place()
  146.         t.up()
  147.         fuelUsed = fuelUsed + 1
  148.         print(fuelUsed)
  149.         t.place()
  150.         t.turnLeft()
  151.         t.turnLeft()
  152.         t.place()
  153.         t.turnRight()
  154.         t.select(stairs)
  155.         t.placeDown()
  156.         t.forward()
  157.         fuelUsed = fuelUsed + 1
  158.         print(fuelUsed)
  159.     end
  160.     for i = 1, amount do
  161.     airBackUp()
  162.     end
  163. end
  164.  
  165. ---------------------------------AIR STAIRS UP END---------------------------------------
  166. function airBackDown()
  167.     turtle.up()
  168.     fuelUsed = fuelUsed + 1
  169.     print(fuelUsed)
  170.     turtle.forward()
  171.     fuelUsed = fuelUsed + 1
  172.     print(fuelUsed)
  173. end
  174. ---------------------------------AIR STAIRS DOWN START---------------------------------------
  175.  
  176. function airStairsDown()
  177.     aboutFace()
  178.     for i = 1, amount do
  179.         t.turnLeft() -- turn left
  180.         t.select(block)
  181.         t.place() -- place left
  182.         aboutFace() -- turn right
  183.         t.place() -- place right
  184.         t.turnLeft()-- back to start position
  185.         t.back()
  186.         fuelUsed = fuelUsed + 1
  187.         print(fuelUsed)
  188.         t.select(stairs)
  189.         t.place()
  190.         t.turnLeft() -- turn left
  191.         t.select(block)
  192.         t.place() -- place left
  193.         aboutFace() -- turn right
  194.         t.place() -- place right
  195.         t.turnLeft()-- back to start position
  196.         t.down()
  197.         fuelUsed = fuelUsed + 1
  198.         print(fuelUsed)
  199.         t.placeDown()
  200.     end
  201.     for z = 1, amount + 1 do
  202.     airBackDown()
  203. end
  204. end
  205. ---------------------------------AIR STAIRS DOWN END---------------------------------------
  206.  
  207. function refuel()
  208. local fuelLvl = turtle.getFuelLevel()
  209. local fuelDistance = amount * 2
  210. local fuelNeeded = (fuelDistance - fuelLvl) / fuelType.coal
  211.     print("Fuel level is " ..fuelLvl)
  212.     if fuelNeeded > 0 then
  213.         for i=1,16 do
  214.             turtle.select(i)
  215.             turtle.refuel(math.ceil(fuelNeeded))
  216.         end
  217.     else print("No fuel needed.")
  218.     end
  219. end
  220.  
  221. function clearTerm()
  222.     term.clear()
  223.     term.setCursorPos(1,1)
  224. end
  225.  
  226. print("Up or Down?")
  227.     direction = io.read()
  228.    
  229. function mainProg()
  230.     if direction == "up" then
  231.         print("Dig yes or no?")
  232.         dig = io.read()
  233.         if dig == "yes" then
  234.             clearTerm()
  235.             repeat
  236.                 print("Be sure to place the turtle at head level." )
  237.                 print("")
  238.                 print("Place stairs in slot " .. stairs)
  239.                 print("")
  240.                 print("Press any key to continue.")
  241.             until os.pullEvent("char")
  242.             clearTerm()
  243.             stairsUp()
  244.         elseif dig == "no" then
  245.             clearTerm()
  246.             repeat
  247.                 print("Place the turtle on ground level.")
  248.                 print("")
  249.                 print("Place blocks in slot " .. block)
  250.                 print("")
  251.                 print("Place stairs in slot " .. stairs)
  252.                 print("")
  253.                 print("Press any key to continue.")
  254.             until os.pullEvent("char")
  255.             clearTerm()
  256.             airStairsUp()
  257.         end
  258.     elseif direction == "down" then
  259.         print("Dig yes or no?")
  260.         dig = io.read()
  261.         if dig == "yes" then
  262.             clearTerm()
  263.             repeat
  264.                 print("Be sure to place the turtle at ground level." )
  265.                 print("")
  266.                 print("Place stairs in slot " .. stairs)
  267.                 print("")
  268.                 print("Press any key to continue.")
  269.             until os.pullEvent("char")
  270.             clearTerm()        
  271.             stairsDown()
  272.         elseif dig == "no" then
  273.             clearTerm()
  274.             repeat
  275.                 print("Place the turtle on ground level.")
  276.                 print("")
  277.                 print("Place blocks in slot " .. block)
  278.                 print("")
  279.                 print("Place stairs in slot " .. stairs)
  280.                 print("")
  281.                 print("Press any key to continue.")
  282.             until os.pullEvent("char")
  283.             clearTerm()
  284.             airStairsDown()
  285.         end
  286.     end
  287. end
  288. refuel()
  289. mainProg()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement