Advertisement
Guest User

platform

a guest
Feb 23rd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. -- * Platform maker 1.2
  2. -- * Made by: Acuena
  3. -- * Usage: platform length width
  4.  
  5. -- Variables
  6. curslot = 2
  7. fuelused = 0
  8. blocksplaced = -1
  9. totalnrblocks = 0
  10.  
  11. -- Functions
  12.  
  13. function moveforward()
  14. while not turtle.forward() do
  15. checkfuel()
  16. end
  17. end
  18.  
  19. function moveback()
  20. while not turtle.back() do
  21. checkfuel()
  22. end
  23. end
  24.  
  25. function checkfuel()
  26. if turtle.getFuelLevel() < 1 then
  27. turtle.select(1)
  28. if not turtle.refuel(1) then
  29. print("No fuel in slot 1, awaiting fuel")
  30. while not turtle.refuel(1) do
  31. end
  32. print("Successfully refueld, continuing")
  33. end
  34. fuelused = fuelused + 1
  35. turtle.select(curslot)
  36. end
  37. end
  38.  
  39. function turnright()
  40. turtle.turnRight()
  41. moveforward()
  42. turtle.turnRight()
  43. end
  44.  
  45. function turnleft()
  46. turtle.turnLeft()
  47. moveforward()
  48. turtle.turnLeft()
  49. end
  50.  
  51. function checkblockcount()
  52. if turtle.getItemCount(curslot) == 0 then
  53. selnextslot()
  54. end
  55. end
  56.  
  57. function selnextslot()
  58. curslot = curslot + 1
  59. if curslot > 16 then
  60. print("Out of blocks, terminating")
  61. error()
  62. end
  63. turtle.select(curslot)
  64. end
  65.  
  66. function place()
  67. checkblockcount()
  68. turtle.placeDown()
  69. blocksplaced = blocksplaced + 1
  70. end
  71.  
  72. function countblocks()
  73. for i = 2,16 do
  74. turtle.select(i)
  75. totalnrblocks = totalnrblocks + turtle.getItemCount(i)
  76. end
  77. if not totalnrblocks == 0 then
  78. totalnrblocks = totalnrblocks + 1
  79. end
  80. turtle.select(curslot)
  81. end
  82.  
  83. function returntostart()
  84. if orient == true then
  85. turtle.turnRight()
  86. for i = 1, width - 1 do
  87. moveforward()
  88. end
  89. turtle.turnRight()
  90. moveback()
  91. elseif orient == false then
  92. turtle.turnLeft()
  93. for i = 1, width - 1 do
  94. moveforward()
  95. end
  96. turtle.turnRight()
  97. for i = 1, length do
  98. turtle.back()
  99. end
  100. end
  101. end
  102.  
  103. -- Code
  104.  
  105. local args = {...}
  106. orient=false
  107. if #args ~= 2 then
  108. print("Usage: platform length width")
  109. return
  110. end
  111.  
  112. length = tonumber(args[1])
  113. width = tonumber(args[2])
  114.  
  115. countblocks()
  116. need = length * width
  117.  
  118. if need > 960 then
  119. print("Unable to carry more than 960 block's")
  120. print("A platform with the size of:")
  121. print(length.."x"..width.." will need "..need.." blocks")
  122. print("Aborting run")
  123. error()
  124. end
  125.  
  126. if totalnrblocks < need then
  127. print("Not enough blocks, aborting")
  128. print("Need: "..need)
  129. print("Have: "..totalnrblocks.." block's")
  130. error()
  131. end
  132.  
  133. moveforward()
  134. place()
  135. for xx = 1,width - 1 do
  136. for x = 1, length-1 do
  137. moveforward()
  138. place()
  139. end
  140.  
  141. if orient == false then -- Should turn right
  142. turnright()
  143. place()
  144. else -- Should turn left
  145. turnleft()
  146. place()
  147. end
  148. orient = not orient
  149. end
  150. for x = 1, length-1 do
  151. moveforward()
  152. place()
  153. end
  154. print("Orient: "..tostring(orient))
  155. returntostart()
  156. print("Platform done")
  157. print("Block's placed: "..blocksplaced)
  158. print("Fuel used: "..fuelused)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement