Advertisement
Wihad

Turm

Aug 6th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. local strtPos={[1]=0, [2]=0, [3]=0} --x,y,z
  2. local curPos= {[1]=strtPos[1], [2]=strtPos[2], [3]=strtPos[3]}
  3. local opt1,opt2="<<<",""
  4. local opt=1
  5.  
  6. function moveForw()
  7.     local try=1
  8.     while not turtle.forward() do
  9.         print("I can't go forward .. try:"..try)
  10.         sleep(1)
  11.         try=try+1
  12.     end
  13. end
  14.  
  15. function moveBack()
  16.     local try=1
  17.     while not turtle.back() do
  18.         print("I can't go back .. try:"..try)
  19.         sleep(1)
  20.         try=try+1
  21.     end
  22. end
  23.  
  24. function moveUp()
  25.     local try=1
  26.     while not turtle.up() do
  27.         print("I can't go up .. try:"..try)
  28.         sleep(1)
  29.         try=try+1
  30.     end
  31.     curPos[2]=curPos[2]+1
  32. end
  33.  
  34. function moveDown()
  35.     local try=1
  36.     while not turtle.down() do
  37.         print("I can't go down .. try:"..try)
  38.         sleep(1)
  39.         try=try+1
  40.     end
  41.     curPos[2]=curPos[2]-1
  42. end
  43.  
  44. function turnL()
  45.     turtle.turnLeft()
  46. end
  47. function turnR()
  48.     turtle.turnRight()
  49. end
  50. function turn2()
  51.     for A=1,2 do
  52.         turnR()
  53.     end
  54. end
  55.  
  56. function digForw()
  57.     while turtle.detect() do
  58.         turtle.dig()
  59.     end
  60.     moveForw()
  61. end
  62.  
  63. function digDown()
  64.     turtle.digDown()
  65.     moveDown()
  66. end
  67.  
  68. function digUp()
  69.     while turtle.detectUp() do
  70.         turtle.digUp()
  71.     end
  72.     moveUp()
  73. end
  74.  
  75. function placeForw()
  76.     if not turtle.detect() then
  77.         local try=1
  78.         while not turtle.place() do
  79.             print("I can't place forw. a block !..Try: "..try)
  80.             try=try+1
  81.             sleep(1)
  82.         end
  83.     end
  84. end
  85.  
  86. function placeUp()
  87.     if not turtle.detectUp() then
  88.         local try=1
  89.         while not turtle.placeUp() do
  90.             print("I can't place up. a block !..Try: "..try)
  91.             try=try+1
  92.             sleep(1)
  93.         end
  94.     end
  95. end
  96.  
  97. function placeDown()
  98.     if not turtle.detectDown() then
  99.         local try=1
  100.         while not turtle.placeDown() do
  101.              print("I can't place down. a block !..Try: "..try)
  102.              try=try+1
  103.              sleep(1)
  104.         end
  105.     end
  106. end
  107.  
  108. function selectSlot()
  109.     for A=1,16 do
  110.         if turtle.getItemCount(A)>12 then
  111.             turtle.select(A)
  112.             break
  113.         end
  114.         if A== 16 then
  115.             gotoStrt()
  116.         end
  117.     end
  118. end
  119.  
  120. function gotoStrt()
  121.     digForw()
  122.     turnL()
  123.     digForw()
  124.     while strtPos[2]~=curPos[2]+1 do
  125.         if opt==1 then moveDown() else moveUp() end
  126.     end
  127.     exit()
  128. end
  129.  
  130. function buildTower()
  131.     if opt==1 then
  132.         digUp()
  133.         digUp()
  134.         digForw()
  135.         turnL()
  136.         while not turtle.detectUp() do
  137.             for A=1,4 do
  138.                 for B=1,3 do
  139.                     digForw()
  140.                     placeDown()
  141.                 end
  142.                 turnL()
  143.                 selectSlot()
  144.             end
  145.             moveUp()
  146.         end
  147.     else
  148.         digDown()
  149.         digDown()
  150.         digForw()
  151.         turnL()
  152.         while not turtle.detectDown() do
  153.             for A=1,4 do
  154.                 for B=1,3 do
  155.                     digForw()
  156.                     placeUp()
  157.                 end
  158.                 turnL()
  159.                 selectSlot()
  160.             end
  161.             moveDown()
  162.         end
  163.     end
  164.     gotoStrt()
  165. end
  166.  
  167. function prntStartScreen()
  168.     term.clear()
  169.     term.setCursorPos(1,1)
  170.     print("Choose your options")
  171.     print("A: build a tower upwards  "..opt1)
  172.     print("B: build a tower downwards  "..opt2)
  173.     term.setCursorPos(1,10)
  174.     print("Enter: to start")
  175.    
  176. end
  177.  
  178. function enterOptions()
  179.     while true do
  180.         local check,key=os.pullEvent("key")
  181.         if check then
  182.             if key==keys.a then opt1="<<<" opt2="" opt=1
  183.             elseif key==keys.b then opt1="" opt2="<<<" opt=0
  184.             elseif key==keys.enter then
  185.                 term.clear()
  186.                 term.setCursorPos(12,5)
  187.                 print("START BUILDING")
  188.                 term.setCursorPos(12,7)            
  189.                 textutils.slowPrint("..............",5)
  190.                 break
  191.             end
  192.             prntStartScreen()
  193.         end
  194.     end
  195. end
  196.  
  197. prntStartScreen()
  198. enterOptions()
  199. buildTower()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement