Advertisement
Lanzr

apv

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