Advertisement
bryceio

Computercraft Clear

Jun 5th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.04 KB | None | 0 0
  1. bry.resetCursor()
  2. w = 0
  3. h = 0
  4. d = 0
  5. confirm = false
  6. repeat
  7. bry.resetCursor()
  8. print("How wide would you like to clear?")
  9. print("-   "..w.."   +")
  10. print("How high would you like to clear?")
  11. print("-   "..h.."   +")
  12. print("How deep would you like to clear?")
  13. print("-   "..d.."   +")
  14. print("Confirm        Cancel")
  15. print(" ")
  16. print("Negative width will go left.")
  17. print("Negative height will go down.")
  18.   local event, button, mouseX, mousey = os.pullEvent("mouse_click")
  19.     if mouseX == 1 and mousey == 2 then
  20.       w = w-1
  21.     elseif mouseX > 4 and mousey == 2 then
  22.       w = w+1
  23.     elseif mouseX == 1 and mousey == 4 then
  24.       h = h-1
  25.     elseif mouseX > 4 and mousey == 4 then
  26.       h = h+1
  27.     elseif mouseX == 1 and mousey == 6 then
  28.       d = d-1
  29.     elseif mouseX > 4 and mousey == 6 then
  30.       d = d+1
  31.     elseif mouseX >= 1 and mouseX <= 8 and mousey == 7 then
  32.       confirm = true
  33.     elseif mouseX >= 15 and mouseX <= 22 and mousey == 7 then
  34.       print("Operation canceled.")
  35.       error()
  36.     end    
  37. until confirm == true
  38.  
  39. if h == 0 or w == 0 or d == 0 then
  40.   bry.resetCursor()
  41.   print("Invalid arguments. No number can be 0.")
  42.   error()
  43. end  
  44.  
  45. if d < 0 then
  46.   d = -d
  47. end
  48.  
  49. bry.resetCursor()
  50. print("You'd like me to clear this area?")
  51. if w > 0 then
  52.   print(w.." wide    (Right)  ")
  53. else
  54.   print(-w.." wide    (Left)")
  55. end
  56. if h > 0 then
  57.   print(h.." high    (Up)     ")
  58. else
  59.   print(-w.." wide    (Down)")
  60. end
  61. print(d.." deep    (Forward)")
  62. print("Confrim        Cancel")
  63. confirm = false
  64. repeat
  65.   local event, button, mouseX, mousey = os.pullEvent("mouse_click")
  66.   if mouseX >= 1 and mouseX <= 8 and mousey == 5 then
  67.     confirm = true
  68.     print("Order confirmed.")
  69.   elseif mouseX >= 15 and mouseX <= 22 and mousey == 5 then
  70.     print("Operation canceled.")
  71.     error()
  72.   end
  73. until confirm == true
  74.  
  75. confrim = false
  76.  
  77. function dig()
  78.   repeat
  79.   turtle.dig()
  80.   turtle.attack()
  81.   until turtle.detect() == false
  82. end
  83.  
  84. if h > 0 then
  85. function digUp()
  86.   repeat
  87.   turtle.digUp()
  88.   turtle.attackUp()
  89.   until turtle.detectUp() == false
  90. end
  91. elseif h < 0 then
  92.   function digUp()
  93.     repeat
  94.       turtle.digDown()
  95.       turtle.attackDown()
  96.     until turtle.detectDown() == false
  97.   end
  98. end
  99.  
  100. function back()
  101.   repeat
  102.   until turtle.back() == true
  103. end
  104.  
  105. if h > 0 then
  106.   function down()
  107.     repeat
  108.       turtle.attackDown()
  109.     until turtle.down() == true
  110.   end
  111. elseif h < 0 then
  112.   function down()
  113.     repeat
  114.       turtle.attackUp()
  115.     until turtle.up() == true
  116.   end
  117. end
  118.  
  119. function xd()
  120.   repeat
  121.   dig()
  122.   until turtle.forward() == true
  123. end
  124.  
  125. if h > 0 then
  126.   function yd()
  127.     repeat
  128.       digUp()
  129.     until turtle.up() == true
  130.   end
  131. elseif h < 0 then
  132.   function yd()
  133.     repeat
  134.       digUp()
  135.     until turtle.down() == true
  136.   end
  137. end
  138.  
  139. if w > 0 then
  140.   function turnRight()
  141.     turtle.turnRight()
  142.   end
  143. elseif w < 0 then
  144.   function turnRight()
  145.     turtle.turnLeft()
  146.   end
  147. end
  148.  
  149. if w > 0 then
  150.   function turnLeft()
  151.     turtle.turnLeft()
  152.   end
  153. elseif w < 0 then
  154.   function turnLeft()
  155.     turtle.turnRight()
  156.   end
  157. end
  158.  
  159. function rex()
  160.   x = x-1
  161. end
  162.  
  163. function inx()
  164.   x = x+1
  165. end
  166.  
  167. function rey()
  168.   y = y-1
  169. end
  170.  
  171. function iny()
  172.   y = y+1
  173. end
  174.  
  175. function rez()
  176.   z = z-1
  177. end
  178.  
  179. function inz()
  180.   z = z+1
  181. end
  182.  
  183. function didDouble()
  184.   double = true
  185. end
  186.  
  187. function reDouble()
  188.   double = false
  189. end
  190.  
  191. if h < 0 then
  192.   h = -h
  193. end
  194.  
  195. if w < 0 then
  196.   w = -w
  197. end
  198.  
  199. z = 0
  200. y = 0
  201. x = 0
  202.  
  203. if w*1 == 1 and h*1 == 1 then
  204.   repeat
  205.     xd()
  206.     inz()
  207.   until z == d*1
  208.   repeat
  209.     back()
  210.     rez()
  211.   until z == 0
  212.   error()
  213. end
  214.  
  215. if w*1 == 2 and h*1 == 1 then
  216.   repeat
  217.     xd()
  218.     inz()
  219.     turnRight()
  220.     dig()
  221.     turnLeft()
  222.   until z == d*1
  223.   repeat
  224.     back()
  225.     rez()
  226.   until z == 0
  227.   error()
  228. end
  229.  
  230. if w*1 == 1 and h*1 >= 2 then
  231.   repeat
  232.     xd()
  233.     inz()
  234.     repeat
  235.       yd()
  236.       iny()
  237.     until y == h-1
  238.     repeat
  239.       down()
  240.       rey()
  241.     until y == 0
  242.   until z == d*1
  243.   repeat
  244.     back()
  245.     rez()
  246.   until z == 0
  247.   error()
  248. end
  249.  
  250. if w*1 == 2 and h*1 >=2 then
  251.   repeat
  252.     xd()
  253.     inz()
  254.     turnRight()
  255.     dig()
  256.     repeat
  257.       yd()
  258.       iny()
  259.       dig()
  260.     until y == h-1
  261.     repeat
  262.       down()
  263.       rey()
  264.     until y == 0
  265.     turnLeft()
  266.   until z == d*1
  267.   repeat
  268.     back()
  269.     rez()
  270.   until z == 0
  271.   error()
  272. end
  273.  
  274. if w*1 >= 3 and h*1 == 1 then
  275.   repeat
  276.     xd()
  277.     inz()
  278.     turnRight()
  279.     repeat
  280.       xd()
  281.       inx()
  282.     until x == w-1
  283.     repeat
  284.       back()
  285.       rex()
  286.     until x == 0
  287.     turnLeft()
  288.   until z == d*1
  289.   repeat
  290.     back()
  291.     rez()
  292.   until z == 0
  293.   error()
  294. end
  295.    
  296.  
  297. repeat
  298.   xd()
  299.   inz()
  300.   turnRight()
  301.    if w*1 >= 2 then
  302.     dig()
  303.    end
  304.   repeat
  305.    if w*1 >= 2 then
  306.      yd()
  307.      dig()
  308.      iny()
  309.      didDouble()
  310.     else
  311.      yd()
  312.      iny()
  313.    end
  314.   until y == h-1
  315.   repeat
  316.     rey()
  317.     down()
  318.   until y == 0
  319.   wr = w-3
  320.   repeat
  321.     if double == true and wr > x then
  322.       xd()
  323.       inx()
  324.       xd()
  325.       inx()
  326.       dig()
  327.       repeat
  328.         yd()
  329.         iny()
  330.         dig()
  331.       until y == h-1
  332.       repeat
  333.         down()
  334.         rey()
  335.       until y == 0
  336.       wr = wr-2
  337.     elseif double == true and wr <= x then
  338.       reDouble()
  339.       xd()
  340.       inx()
  341.       xd()
  342.       inx()
  343.       repeat
  344.         yd()
  345.         iny()
  346.       until y == h-1
  347.       repeat
  348.         down()
  349.         rey()
  350.       until y == 0
  351.       wr = wr-1
  352.     elseif double == false and wr > x then
  353.       didDouble()
  354.       xd()
  355.       inx()
  356.       dig()
  357.       repeat
  358.         yd()
  359.         dig()
  360.         iny()
  361.       until y == h-1
  362.       repeat
  363.         down()
  364.         rey()
  365.       until y == 0
  366.       wr = wr-2
  367.     else
  368.       xd()
  369.       inx()
  370.       repeat
  371.         yd()
  372.         iny()
  373.       until y == h-1
  374.       repeat
  375.         down()
  376.         rey()
  377.       until y == 0
  378.       wr = wr-1
  379.     end
  380.   until wr <= 0
  381.   repeat
  382.     back()
  383.     rex()
  384.   until x == 0
  385.   x = 0
  386.   turnLeft()
  387. until z == d*1
  388. repeat
  389.   back()
  390.   rez()
  391. until z == 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement