Advertisement
Lanzr

ap

Oct 21st, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. local target = 0
  2. if(arg[4] == nil) then
  3. print("not enough arg")
  4. return
  5. end
  6.  
  7.  
  8. local length = tonumber(arg[1])
  9. local weight = tonumber(arg[2])
  10. local pMode = nil
  11. local orient = "RIGHT"
  12.  
  13.  
  14. local turntFlag = false
  15. if(arg[4] == "l") then
  16. orient = "LEFT"
  17. turntFlag = true
  18. elseif (arg[4] == "r") then
  19. orient = "RIGHT"
  20. else
  21. print("not valid orient!")
  22. return
  23. end
  24.  
  25. if(arg[3] == "ver") then
  26. pMode = "VER"
  27. turntFlag = false
  28. elseif (arg[3] == "hor") then
  29. pMode = "HOR"
  30. else
  31. print("not valid mode!")
  32. return
  33. end
  34.  
  35. print("input confirm to start work");
  36. if(io.read() ~= "confirm" ) then
  37. print("u not confirm!")
  38. return
  39. end
  40.  
  41. print("start work!")
  42. local emptyFlag =false
  43. local bkslot = 2
  44.  
  45. local function turtleSelfCheck()
  46. -- check fuel
  47. if(turtle.getFuelLevel() < 100) then
  48. turtle.select(1)
  49. turtle.refuel(1)
  50. end
  51. -- check space
  52. turtle.select(bkslot)
  53. if(emptyFlag == false) then
  54. while (turtle.getItemCount() == 0) do
  55. bkslot = bkslot + 1
  56. if(turtle.getItemCount(2) ~= 0) then
  57. bkslot = 2
  58. break
  59. end
  60. if(bkslot > 16) then
  61. os.shutdown()
  62. end
  63. turtle.select(bkslot)
  64. end
  65. end
  66.  
  67. end
  68.  
  69.  
  70. local function turtleMove(edgeFlag)
  71. if(pMode == "HOR") then
  72. if(edgeFlag) then
  73. if(turntFlag == false) then
  74. turtle.turnRight()
  75. turtle.forward()
  76. turtle.turnRight()
  77. else
  78. turtle.turnLeft()
  79. turtle.forward()
  80. turtle.turnLeft()
  81. end
  82. turntFlag = not turntFlag
  83. else
  84. turtle.forward()
  85. end
  86. elseif (pMode == "VER") then
  87. if(turntFlag == false) then
  88. if(edgeFlag) then
  89. if(orient == "RIGHT") then
  90. turtle.turnRight()
  91. turtle.forward()
  92. turtle.turnLeft()
  93. turntFlag = not turntFlag
  94. else
  95. turtle.turnLeft()
  96. turtle.forward()
  97. turtle.turnRight()
  98. turntFlag = not turntFlag
  99. end
  100. else
  101. turtle.up()
  102. end
  103. else
  104. if(edgeFlag) then
  105. if(orient == "RIGHT") then
  106. turtle.turnRight()
  107. turtle.forward()
  108. turtle.turnLeft()
  109. turntFlag = not turntFlag
  110. else
  111. turtle.turnLeft()
  112. turtle.forward()
  113. turtle.turnRight()
  114. turntFlag = not turntFlag
  115. end
  116. else
  117. turtle.down()
  118. end
  119. end
  120. end
  121. end
  122.  
  123. local eFlag = false
  124. while true do
  125. local count = 0
  126. while true do
  127. -- self check
  128. turtleSelfCheck()
  129. -- place
  130. if(pMode == "HOR") then
  131. turtle.placeDown()
  132. elseif(pMode == "VER") then
  133. turtle.place()
  134. end
  135. -- move
  136. if(turtle.detect()) then
  137. if(turntFlag == false) then
  138. turtle.turnRight()
  139. turtle.forward()
  140. turtle.turnRight()
  141. else
  142. turtle.turnLeft()
  143. turtle.forward()
  144. turtle.turnLeft()
  145. end
  146. turntFlag = not turntFlag
  147. break
  148. else
  149. turtle.forward()
  150. end
  151.  
  152. count = count + 1
  153. --
  154. end
  155. turtle.back()
  156. turtle.placeDown()
  157. while (count > target) do
  158. turtleSelfCheck()
  159.  
  160. turtle.forward()
  161. turtle.placeDown()
  162. count = count -1
  163. end
  164. if(turntFlag == false) then
  165. turtle.turnRight()
  166. turtle.forward()
  167. turtle.turnRight()
  168. else
  169. turtle.turnLeft()
  170. turtle.forward()
  171. turtle.turnLeft()
  172. end
  173. turntFlag = not turntFlag
  174. end
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement