Advertisement
Guest User

test2

a guest
Apr 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None | 0 0
  1. -- Mining Program --
  2.  
  3. function intro(quit)
  4. -- intro function just reads input from player to lead to menu or the help doc --
  5.   if quit then
  6.     print("quitting")
  7.     return
  8.   else
  9.       print("-------- Mining Program --------")
  10.       print("--------------------------------")
  11.       print("Press H for help or S for start")
  12.       print("You can quit typing exit")
  13.       print(" ")
  14.       write("--> ")
  15.       inputhelp = string.lower(read())
  16.      
  17.       if inputhelp == "h" then
  18.         playerhelp()
  19.       elseif inputhelp == "exit" then
  20.         print("quitting")
  21.       elseif inputhelp == "s" then
  22.         menu()
  23.       else
  24.         intro()
  25.       end
  26.   end
  27. end
  28.  
  29. function playerhelp()
  30. -- helpfunction --
  31.  
  32.   print("HA, too bad")
  33.   sleep(2)
  34.   menu()
  35. end
  36.  
  37. function menu()
  38. --prints menu, shows settings --
  39.  
  40.   term.clear()
  41.   print("----------- Main Menu -----------")
  42.   print("---------------------------------")
  43.   print("--- Type in shortcuts like: T ---")
  44.   print("--- Type exit for quitting    ---")
  45.   print(" ")
  46.   write("Number corridors (-C)   = ")
  47.   write(corridors)
  48.   print(" ")
  49.   write("Length corridors (-L)   = ")
  50.   write(length)
  51.   print(" ")
  52.   write("Torches (-T)            = ")
  53.   write(torch)
  54.   print(" ")
  55.   write("Enderchest (-E)         = ")
  56.   write(ender)
  57.   print(" ")
  58.   write("Gap (-g)                = ")
  59.   write(gap)
  60.   print(" ")
  61.   write("--> ")
  62.   playerinput = string.lower(read())
  63.  
  64.   if playerinput == "c" then
  65.     setcorridors()
  66.   elseif playerinput == "l" then
  67.     setlength()
  68.   elseif playerinput == "t" then
  69.     settorch()
  70.   elseif playerinput == "e" then
  71.     setender()
  72.   elseif playerinput == "s" then
  73.     mainfunction()
  74.   elseif playerinput == "g" then
  75.     setgap()
  76.   elseif playerinput == "exit" then
  77.     intro(1)
  78.   else
  79.     menu()
  80.   end
  81. end    
  82.  
  83. function setcorridors()
  84.   write("-- set corridor number to? :")
  85.   corridors = tonumber(read())
  86.   menu()
  87. end    
  88.  
  89. function setlength()
  90.   write("-- set corridor length to? :")
  91.   length = tonumber(read())
  92.   menu()
  93. end
  94.  
  95. function settorch()
  96.   write("-- Turn torches on or off? :")
  97.   torch = read()
  98.   menu()
  99. end
  100.  
  101. function setender()
  102.   write("-- Turn Enderchest on or off?:")
  103.   ender = read()
  104.   menu()
  105. end
  106.  
  107. function setgap()
  108.   write("-- set gap to?: ")
  109.   gap = tonumber(read())
  110.   menu()
  111. end
  112.  
  113. function mainfunction()
  114.   i=0
  115.   while i<corridors do
  116.     t=0
  117.     while t<length do
  118.       digup()
  119.       digforward()
  120.       turtle.forward()
  121.       safepath()
  122.       if torch == "on" then
  123.         checktorch()
  124.       end
  125.       if ender == "on" then
  126.         checkender()
  127.       end
  128.       t = t+1
  129.     end
  130.  
  131.   turning()
  132.   i = i+1
  133.   end
  134. end
  135.  
  136. function turning()
  137.   if turn == 0 then
  138.     cleanleft()
  139.     turtle.turnLeft()
  140.   else
  141.     cleanright()
  142.     turtle.turnRight()
  143.   end
  144.   step = 0
  145.     while step<gap do
  146.       digup()
  147.       digforward()
  148.       turtle.forward()
  149.       step=step+1
  150.     end
  151.   if turn == 0 then
  152.     turtle.turnLeft()
  153.     turn = 1
  154.   else
  155.     turtle.turnRight()
  156.     turn = 0
  157.   end
  158. end
  159.  
  160. function cleanleft()
  161.   turtle.turnRight()
  162.   step = 0
  163.   while step<gap do  
  164.     digup()
  165.     digforward()
  166.     turtle.forward()
  167.     step = step+1
  168.   end
  169.   turtle.turnRight()
  170.   turtle.turnRight()
  171.   for i=1,gap do
  172.     turtle.forward()
  173.   end
  174.  
  175.  
  176. function checkender()
  177.   count = turtle.getItemCount(14)
  178.   if count > 0 then
  179.     emptyender()
  180.   end
  181. end
  182.  
  183. function emptyender()
  184.   turtle.digUp()
  185.   turtle.select(1)
  186.   turtle.Up()
  187.   turtle.placeDown()
  188.   s = 4
  189.   repeat
  190.     turtle.select(s)
  191.     turtle.dropDown()
  192.     s = s+1
  193.   until s>15
  194.   turtle.digDown()
  195.   turtle.Down()
  196.   turtle.select(3)
  197.   turtle.placeDown()
  198. end
  199.  
  200.  
  201. function checktorch()
  202.   if torches > 10 then
  203.     turtle.turnLeft()
  204.     turtle.turnLeft()
  205.     turtle.select(2)
  206.     turtle.place()
  207.     turtle.turnLeft()
  208.     turtle.turnLeft()
  209.     torches = 0
  210.    else
  211.      torches = torches+1
  212.    end
  213. end
  214.    
  215. function safepath()
  216.   if turtle.detectDown() == false then
  217.     select(3)
  218.     turtle.placeDown()
  219.   end
  220. end
  221.  
  222. function digup()
  223.   while turtle.detectUp() do
  224.     turtle.digUp()
  225.     sleep(0.5)
  226.   end  
  227. end
  228.  
  229. function digforward()
  230.   while turtle.detect() do
  231.     turtle.dig()
  232.     sleep(0.5)
  233.   end
  234. end
  235.  
  236. inputs = {...} or {10,20,"On","Off","Off"}
  237. corridors = inputs[1] or 10
  238. length = inputs[2] or 20
  239. torch = inputs [3] or "On"
  240. ender = inputs [4] or "Off"
  241. start = inputs [5] or "Off"
  242. gap = 2
  243. torches = 0
  244. turn = 0
  245. if string.lower(start) == "on" then
  246.   mainfunction()
  247. else
  248.   intro()
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement