Kentngo

MTv1.1

Mar 16th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.93 KB | None | 0 0
  1. function AskTorch()
  2.     shell.run("clear")
  3.     print "My name is Sebastian, I would be happy to serve you."
  4.     print ("I have the strength to go ".. turtle.getFuelLevel().. " blocks today.")
  5.     io.write "Would you like me to place torches as well? (y/n) "
  6.     torchperm = io.read()
  7.     if torchperm == "y" then
  8.         print "If you have any torches, I would advise you to place them in my last slot,"
  9.         if turtle.getItemCount(16) == 0 then
  10.             print "but they do not seem to be there at the moment. Might I advise you to place them now?"
  11.             print ""
  12.         end
  13.     end
  14.     if torchperm ~= "y" then
  15.         if torchperm ~= "n" then
  16.             print ""
  17.             print "Your commands are obscure. Could you repeat that please?"
  18.             print ""   
  19.         end
  20.     end
  21.     return torchperm
  22. end
  23.  
  24. function AskChest()
  25.     io.write "Would you like me to empty out my inventory every so often? (y/n) "
  26.     chestperm = io.read()
  27.     if chestperm == "y" then
  28.         print ""
  29.         print "Please place chests in my second slot."
  30.         print ""
  31.     end
  32.     if chestperm ~= "y" then
  33.         if chestperm ~= "n" then
  34.             print ""
  35.             print "Your commands are obscure. Could you repeat that please?"
  36.             print ""
  37.             AskChest()
  38.         end
  39.     end
  40.     return chestperm
  41. end
  42.  
  43. function AskFuel()
  44.     io.write "Would you like me to use fuel in my inventory to keep working? (y/n) "
  45.     fuelperm = io.read()
  46.     if fuelperm == "y" then
  47.         print ""
  48.         print "I will use them to your bidding."
  49.         print ""
  50.     end
  51.     if fuelperm ~= "y" then
  52.         if fuelperm ~= "n" then
  53.             print ""
  54.             print "Your commands are obscure. Could you repeat that please?"
  55.             print ""
  56.             AskFuel()
  57.         end
  58.     end
  59.     return fuelperm
  60. end
  61.  
  62. function AskSide()
  63.     io.write "Shall I dig it to the right or to the left? "
  64.     side = io.read()
  65.     if side ~= "right" then
  66.         if side ~= "left" then
  67.             print ""
  68.             print "Your commands are obscure. Could you repeat that please?"
  69.             print ""
  70.             AskSide()
  71.         end
  72.     end
  73.     return side
  74. end
  75.  
  76. function AskHeight()
  77.     io.write "How high of a tunnel would you like me to dig? "
  78.     height = io.read()
  79.     if not tonumber(height) then
  80.         print ""
  81.         print "That is not a number."
  82.         print ""
  83.         AskHeight()
  84.     else
  85.         height = tonumber(height)
  86.     end
  87.     if height > 256 then
  88.         print ""
  89.         print "You give me impossible tasks."
  90.         print ""
  91.         AskHeight()
  92.     end
  93.     if height < 1 then
  94.         print ""
  95.         print "I'm afraid I can not dig that way."
  96.         print ""
  97.         AskHeight()
  98.     end
  99.     return height
  100. end
  101.  
  102. function AskWidth()
  103.     io.write "How wide would you like it to be? "
  104.     width = io.read()
  105.     if not tonumber(width) then
  106.         print ""
  107.         print "That is not a number."
  108.         print ""
  109.         AskWidth()
  110.     else
  111.         width = tonumber(width)
  112.     end
  113.     if width < 1 then
  114.         print ""
  115.         print "I'm afraid I can not dig that way. "
  116.         print ""
  117.         AskWidth()
  118.     end
  119.     return width
  120. end
  121.  
  122. function AskLength()
  123.     io.write "How long should the tunnel be dug? "
  124.     length = io.read()
  125.     if not tonumber(length) then
  126.         print ""
  127.         print "That is not a number."
  128.         print ""
  129.         AskLength()
  130.     else
  131.         length = tonumber(length)
  132.     end
  133.     if length < 1 then
  134.         print ""
  135.         print "I'm afraid I can not dig that way."
  136.         print ""
  137.         AskLength()
  138.     end
  139.     return length
  140. end
  141.  
  142. function point()
  143.     while not turtle.forward() do
  144.         turtle.dig()
  145.     end
  146.     autofuel()
  147. end
  148.  
  149. function line(width)
  150.     p = 1
  151.     while width > p do
  152.         point()
  153.         p = p + 1
  154.     end
  155. end
  156.  
  157. function raise()
  158.     while not turtle.up() do
  159.         turtle.digUp()
  160.     end
  161.     autofuel()
  162. end
  163.  
  164. function drop()
  165.     while not turtle.down() do
  166.         turtle.digDown()
  167.     end
  168.     autofuel()
  169. end
  170.  
  171. function degreeangle()
  172.     turtle.turnLeft()
  173.     turtle.turnLeft()
  174. end
  175.  
  176. function layer()
  177.     line(width)
  178.     degreeangle()
  179. end
  180.  
  181. function store()
  182.     turtle.digDown()
  183.     turtle.select(2)
  184.     turtle.placeDown()
  185.     if torchperm == "y" then
  186.         for slot = 3, 15 do
  187.             turtle.select(slot)
  188.             turtle.dropDown()
  189.         end
  190.     end
  191.     if torchperm ~= "y" then
  192.         for slot = 3, 16 do
  193.             turtle.select(slot)
  194.             turtle.dropDown()
  195.         end
  196.     end
  197.     turtle.select(1)
  198. end
  199.  
  200. function returnodd()
  201.     yreturn = 1
  202.     zreturn = 1
  203.     while zreturn < width do
  204.         point()
  205.         zreturn = zreturn + 1
  206.     end
  207.     while yreturn < height do
  208.         drop()
  209.         yreturn = yreturn + 1
  210.     end
  211. end
  212.  
  213. function returneven()
  214.     yreturn = 1
  215.     while yreturn < height do
  216.         drop()
  217.         yreturn = yreturn + 1
  218.     end
  219. end
  220.  
  221. function squareright(height,width)
  222.     y = 0
  223.     loop = 0
  224.     point()
  225.     turtle.turnRight()
  226.     while y < height do
  227.         layer()
  228.         if loop == 0 then
  229.             loop = loop + 1
  230.         else
  231.             loop = loop - 1
  232.         end
  233.         y = y + 1
  234.         if height > y then
  235.             raise()
  236.         end
  237.         if y == height then
  238.             if loop == 0 then
  239.                 returneven()
  240.                 turtle.turnLeft()
  241.             else
  242.                 returnodd()
  243.                 turtle.turnRight()
  244.             end
  245.         end
  246.     end
  247. end
  248.  
  249. function squareleft(height,width)
  250.     y = 0
  251.     loop = 0
  252.     point()
  253.     turtle.turnLeft()
  254.     while y < height do
  255.         layer()
  256.         if loop == 0 then
  257.             loop = loop + 1
  258.         else
  259.             loop = loop - 1
  260.         end
  261.         y = y + 1
  262.         if height > y then
  263.             raise()
  264.         end
  265.         if y == height then
  266.             if loop == 0 then
  267.                 returneven()
  268.                 turtle.turnRight()
  269.             else
  270.                 returnodd()
  271.                 turtle.turnLeft()
  272.             end
  273.         end
  274.     end
  275. end
  276.  
  277. function prism(length,height,width)
  278.     x = 0
  279.     t = 1
  280.     c = 1
  281.     StartFuel()
  282.     if side == "right" then
  283.         while length > x do
  284.             squareright(height,width)
  285.             x = x + 1
  286.             autotorch()
  287.             autostore()
  288.         end
  289.     end
  290.     if side ~= "right" then
  291.         if side == "left" then
  292.             while length > x do
  293.                 squareleft(height,width)
  294.                 x = x + 1
  295.                 autotorch()
  296.                 autostore()
  297.             end
  298.         end
  299.     end
  300. end
  301.  
  302. function autostore()
  303.     if chestperm == "y" then
  304.         c = c + 1
  305.     end
  306.     if c == 5 then
  307.         store()
  308.         c = 1
  309.     end
  310. end
  311.  
  312. function autotorch()
  313.     if torchperm == "y" then
  314.         t = t + 1
  315.     end
  316.     if t == 5 then
  317.         degreeangle()
  318.         raise()
  319.         turtle.select(16)
  320.         turtle.place()
  321.         turtle.select(1)
  322.         drop()
  323.         degreeangle()
  324.         t = 1
  325.     end
  326. end
  327.  
  328. function autofuel()
  329.     while turtle.getFuelLevel() < 1 do
  330.         if fuelperm == "y" then
  331.             for slot = 1, 16 do
  332.                 turtle.select(slot)
  333.                 turtle.refuel(1)
  334.                 if turtle.getFuelLevel() > 0 then
  335.                     turtle.select(1)
  336.                     break
  337.                 end
  338.             end
  339.         end
  340.         NeedFuel()
  341.     end
  342. end
  343.  
  344. function NeedFuel()
  345.     if turtle.getFuelLevel() == 0 then
  346.         print ""
  347.         print "I will not be able to work until I receive fuel."
  348.         print ""
  349.         while turtle.getFuelLevel() == 0 do
  350.             turtle.refuel(1)
  351.             sleep(1)
  352.         end
  353.     end
  354.     print ""
  355.     print "I will start working immediately."
  356.     print ""
  357. end
  358.  
  359. function StartFuel()
  360.     turtle.select(1)
  361.     if turtle.getFuelLevel() == 0 then
  362.         print ""
  363.         print "Please place some fuel in my first slot so that I can start working."
  364.         print ""
  365.         while turtle.getFuelLevel() == 0 do
  366.             turtle.refuel()
  367.             sleep(1)
  368.         end
  369.     end
  370.     print ""
  371.     print "I will begin immediately."
  372.     print ""
  373. end
  374.  
  375. function backtostart()
  376.     displacement = 0
  377.     degreeangle()
  378.     while displacement < length do
  379.         point()
  380.         displacement = displacement + 1
  381.     end
  382.     degreeangle()
  383.     print ""
  384.     print "I have finished my task. I await your next command."
  385.     print ""
  386. end
  387.  
  388. AskTorch()
  389. AskFuel()
  390. AskChest()
  391. AskSide()
  392. AskHeight()
  393. AskWidth()
  394. AskLength()
  395. prism(length,height,width)
  396. backtostart(length)
Advertisement
Add Comment
Please, Sign In to add comment