Advertisement
QQII

Torch Turtle V0.1

Apr 7th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. --Place Torches V0.1 by QQII
  2. --Declerations
  3. local Arguments = { ... }       --Program arguments
  4. local length = tonumber(Arguments[1]) or 0
  5. local width = tonumber(Arguments[2]) or length
  6.  
  7. --Functions
  8. local function refuel()
  9.     while turtle.getFuelLevel() <= 0 do
  10.         shell.run("refuel", "all")
  11.         if turtle.getFuelLevel() <= 0 then
  12.             print("ERROR: out of fuel")
  13.             read()
  14.         end
  15.     end
  16.     turtle.select(1)
  17. end
  18.  
  19. local function forward(l)       --Moves forward
  20.     for i = 1, l do
  21.         refuel()
  22.         while not turtle.forward() do
  23.             if not turtle.attack() then
  24.                 turtle.dig()
  25.             end
  26.         end
  27.     end
  28. end
  29.  
  30. local function inventory_sort()     --Fills the first slot with items from the other slots
  31.     for i = 2, 16 do
  32.         if turtle.getItemSpace(1) == 0 then
  33.             break
  34.         end
  35.         turtle.select(i)
  36.         turtle.transferTo(1, turtle.getItemCount(i))
  37.     end
  38.     turtle.select(1)
  39. end
  40.  
  41. local function place_down()     --Places a block below the turtle
  42.     while not turtle.placeDown() do
  43.         turtle.digDown()
  44.         inventory_sort()
  45.         if turtle.getItemCount(1) == 0 then
  46.             print("ERROR: out of items")
  47.             read()
  48.         end
  49.     end
  50. end
  51.  
  52. --User Inputs
  53. print("The turtle will place torches")
  54. if length <= 0 then
  55.     io.write("Length: ")
  56.     while length <= 0 do
  57.         length = tonumber(read())
  58.     end
  59. else
  60.     print("Length: " .. length)
  61. end
  62. if  width <= 0 then
  63.     io.write("Width: ")
  64.     while width <= 0 do
  65.         width = tonumber(read())
  66.     end
  67. else
  68.     print("Width: " .. width)
  69. end
  70. length = math.floor(length / 6) + 1
  71. width = math.floor(width / 6) + 1
  72.  
  73. --Main Script
  74. refuel()
  75. for i = 2, width do
  76.     for i = 2, length do
  77.         place_down()
  78.         forward(6)
  79.     end
  80.     place_down()
  81.     if i % 2 ~= 0 then
  82.         turtle.turnLeft()
  83.         forward(6)
  84.         turtle.turnLeft()
  85.     elseif i % 2 == 0 then
  86.         turtle.turnRight()
  87.         forward(6)
  88.         turtle.turnRight()
  89.     end
  90. end
  91. place_down()
  92. for i = 2, length do
  93.     forward(6)
  94.     place_down()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement