Advertisement
iMontouch

placement Turtle 1.0

Jul 16th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. -- Session Persistance
  2. if(not fs.exists('startup')) then
  3. local file = io.open('startup', 'w')
  4. file:write("shell.run(\'placer\')")
  5. file:close()
  6. end
  7.  
  8. -- Functions
  9. function refuel(fuel)
  10.         if(turtle.getFuelLevel() >= fuel) then
  11.                 return true
  12.         end
  13.         print('Refueling')
  14.         turtle.select(9)
  15.         while(not turtle.placeUp()) do
  16.                 turtle.digUp()
  17.                 turtle.attackUp()
  18.         end
  19.         turtle.select(16)
  20.         while(not turtle.suckUp()) do
  21.                 sleep('No fuel found. Sleeping.', 10)
  22.         end
  23.         turtle.refuel(64)
  24.         turtle.select(9)
  25.         turtle.digUp()
  26.         if(turtle.getFuelLevel() <= fuel) then
  27.                 sleep('Refueling failed!', 10)
  28.                 dump()
  29.                 refuel(200)
  30.         end
  31. end
  32.  
  33. -- Refuel & Variables
  34. refuel(500)
  35. all = 0
  36.  
  37. -- Endless Placing Process
  38. while(true) do
  39.    
  40. -- Fill the turtle with materials
  41. if turtle.getItemCount(1) == 0 then
  42. print('Obtaining Destination Chests for Slot 1')
  43. turtle.select(6)
  44. while(not turtle.placeUp()) do
  45. turtle.digUp()
  46. turtle.attackUp()
  47. end
  48. turtle.select(1)
  49. while(not turtle.suckUp()) do
  50. print("No Chests found. Sleeping.")
  51. sleep(10)
  52. end
  53. turtle.select(6)
  54. turtle.digUp()
  55. end
  56.  
  57. if turtle.getItemCount(2) == 0 then
  58. print('Obtaining Fuel Chests for Slot 2')
  59. turtle.select(7)
  60. while(not turtle.placeUp()) do
  61. turtle.digUp()
  62. turtle.attackUp()
  63. end
  64. turtle.select(2)
  65. while(not turtle.suckUp()) do
  66. print("No Chests found. Sleeping.")
  67. sleep(10)
  68. end
  69. turtle.select(7)
  70. turtle.digUp()
  71. end
  72.  
  73. if turtle.getItemCount(3) == 0 then
  74. print('Obtaining Turtles for Slot 3')
  75. turtle.select(8)
  76. while(not turtle.placeUp()) do
  77. turtle.digUp()
  78. turtle.attackUp()
  79. end
  80. turtle.select(3)
  81. while(not turtle.suckUp()) do
  82. print("No Turtles found. Sleeping.")
  83. sleep(10)
  84. end
  85.  
  86. print("Error4")
  87.  
  88. turtle.select(8)
  89. turtle.digUp()
  90. end
  91.  
  92. -- Check how much turtles are available
  93. x = turtle.getItemCount(1)
  94. y = turtle.getItemCount(2)
  95. z = turtle.getItemCount(3)
  96. if (x>y) then
  97.     if (y>z) then
  98.         turtles = z
  99.     else turtles = y
  100.     end
  101. else
  102.     if (x>z) then
  103.         turtles = z
  104.     else turtles = x
  105.     end
  106. end
  107.  
  108. -- Place them Turtles
  109. for i = 1,turtles do
  110.    
  111. -- Place a Turtle & load it
  112. turtle.turnLeft()
  113. turtle.select(3)
  114. turtle.place()
  115. turtle.select(1)
  116. turtle.drop(1)
  117. turtle.select(2)
  118. turtle.drop(1)
  119. turtle.turnRight()
  120.  
  121. -- Place the Drive & load it
  122. turtle.back()
  123. turtle.select(4)
  124. turtle.place()
  125. turtle.select(5)
  126. turtle.drop(1)
  127.  
  128. -- Start the Turtle
  129. turtle.up()
  130. turtle.forward()
  131. turtle.turnLeft()
  132. turtle.forward()
  133. peripheral.call("bottom", "turnOn")
  134. turtle.back()
  135. turtle.turnRight()
  136. turtle.back()
  137. turtle.down()
  138.  
  139. -- Unload Drive & Remove it
  140. turtle.select(5)
  141. turtle.suck()
  142. turtle.select(4)
  143. turtle.dig()
  144. turtle.suck()
  145.  
  146. -- Move to next turtle and refuel
  147. turtle.forward()
  148. turtle.forward()
  149. refuel(500)
  150.  
  151. -- End Turtle Placing
  152. end
  153. all = all + turtles
  154. print('Number of Turtles placed: '..all)
  155.  
  156. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement