kreezxil

Turtlescript Platform II Command

Jul 23rd, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. --[[
  2. Credit to Zach Dyer for the original program that I based this on
  3. 'Easy Platform Builder'.
  4.  
  5. Current version: 2.0
  6. Pastebin: M0i8fDU5
  7.  
  8. Changelog:
  9. 5/20/2014 - added torch placing, block detection
  10. 5/31/2014 - added mob attacking, better block detection,
  11. inventory requests when empty, resume on keypress.
  12. --]]
  13.  
  14. local tArgs = {...}
  15.  
  16. local length = tonumber(tArgs[1])
  17. local width = tonumber(tArgs[2])
  18. local torch_interval = tonumber(tArgs[3])
  19.  
  20. if torch_interval == nil then
  21. torch_interval = 0
  22. end
  23.  
  24. local turnRight = true
  25. local slot = 1
  26. local interval = 0
  27.  
  28. function pauseAnyKey()
  29. -- if event == "key" and p1 == keys.q then
  30. while true do
  31. local event, p1,p2,p3 = os.pullEvent()
  32. if event == "key" then
  33. return p1
  34. end
  35. sleep(0.5)
  36. end
  37. end
  38.  
  39. -- Kudos to BlockSmith on ComputerCraft.info forums for the suggestion!
  40. function refuel(dim1,dim2)
  41. dim1 = dim1 or 1
  42. dim2 = dim2 or 1
  43. fuelReq = dim1 * dim2
  44. turtle.select(15)
  45. while (turtle.getFuelLevel() < fuelReq) do
  46. --inform the user that the turtle is out of fuel
  47. print("Waiting for fuel in slot 15...")
  48. print("Press any key to continue.")
  49. pauseAnyKey()
  50. -- use all of the fuel in slot 15
  51. turtle.refuel()
  52. -- then go back and check the level again
  53. end
  54.  
  55. -- select the active slot
  56. turtle.select(slot)
  57. end
  58.  
  59. function flip()
  60. turtle.turnRight()
  61. turtle.turnRight()
  62. end
  63.  
  64. function digDetect()
  65. while turtle.detect() do
  66. turtle.dig()
  67. end
  68. end
  69.  
  70. function psycho()
  71. turtle.attack()
  72. turtle.attackUp()
  73. turtle.attackDown()
  74. turtle.turnLeft()
  75. turtle.attack()
  76. turtle.turnRight()
  77. turtle.turnRight()
  78. turtle.attack()
  79. turtle.turnLeft()
  80. end
  81.  
  82. function digDetectUp()
  83. while turtle.detectUp() do
  84. turtle.digUp()
  85. end
  86. end
  87.  
  88. function tryForward()
  89. while not turtle.forward() do
  90. psycho() --turtle.attack()
  91. turtle.dig()
  92. end
  93. end
  94.  
  95. function tryPlaceDown(mode)
  96. mode = mode or "ignore me"
  97. while not turtle.placeDown() do
  98. if mode == "dig" then
  99. turtle.digDown()
  100. end
  101. --turtle.attackDown()
  102. psycho()
  103. turtle.attack()
  104. end
  105. end
  106.  
  107. function findInventory()
  108. for i=slot,14 do
  109. if turtle.getItemCount(i) > 0 then
  110. return i
  111. end
  112. end
  113. for i=1,slot-1 do
  114. if turtle.getItemCount(i) > 0 then
  115. return i
  116. end
  117. end
  118. return -1
  119. end
  120.  
  121. function torchPlacer()
  122. turtle.select(16)
  123. if turtle.getItemCount(16) == 0 then
  124. print("I need more torches!")
  125. print("Put more torches in slot 16 and press any key to make me resume!")
  126. pauseAnyKey()
  127. end
  128. digDetectUp()
  129. turtle.up()
  130. flip()
  131. digDetect()
  132. flip()
  133. turtle.back()
  134. tryPlaceDown()
  135. --turtle.placeDown()
  136. tryForward()
  137. turtle.down()
  138. end
  139.  
  140. if width == nil then
  141. print("1. Place turtle facing direction of said platform on left side.")
  142. print("2. Load turtle with materials for the platform. If placing torches, add light source blocks to slot 16.")
  143. print("3. Type 'platform <length> <width> [torch_interval]'")
  144. return
  145. end
  146.  
  147. turtle.select(slot)
  148.  
  149.  
  150. -- set the initial fuel load
  151. refuel(length,width)
  152. tryForward()
  153.  
  154. for j = 1, width, 1 do
  155.  
  156. for i = 1, length, 1 do
  157. if turtle.getItemCount(slot) == 0 then
  158. x = findInventory()
  159. while x == -1 do
  160. if x == -1 then
  161. print("I ran out of materials!")
  162. print("Put mats in slots 1 to 14 then")
  163. print("press any key to continue.")
  164. pauseAnyKey()
  165. x = findInventory()
  166. end
  167. end
  168. slot = x
  169. end
  170.  
  171. turtle.select(slot)
  172. tryPlaceDown("dig")
  173.  
  174. if i < length then
  175. digDetect()
  176. tryForward()
  177. end
  178.  
  179. if torch_interval > 0 then
  180. interval = interval + 1
  181. if interval == torch_interval then
  182. interval = 0
  183. torchPlacer()
  184. end
  185. end
  186.  
  187. end
  188.  
  189. if j < width then
  190.  
  191. if turnRight == true then
  192. turtle.turnRight()
  193. digDetect()
  194. tryForward()
  195. turtle.turnRight()
  196. turnRight = false
  197. else
  198. turtle.turnLeft()
  199. digDetect()
  200. tryForward()
  201. turtle.turnLeft()
  202. turnRight = true
  203. end
  204.  
  205. end
  206.  
  207. refuel(5) -- cursory check for fuel
  208. end
Add Comment
Please, Sign In to add comment