Posted 02 December 2012 - 10:03 PM
Well this is my first released script.
It will build a bunker for you with your given size.
Program will thell where to put items and fuel.
Syntax is : bunker <Length> <Width> <Height> <Door>
turtle starts at bottom left of bunker.
if you set door to 1 it will place the door 1 block to the right from where it started.
will not build the floor (if you want tell me in comment and i will add it.)
Pastebin: http://pastebin.com/qni0qx2r
Hope it helps somuone.comments are greatly appreciated
It will build a bunker for you with your given size.
Program will thell where to put items and fuel.
Syntax is : bunker <Length> <Width> <Height> <Door>
turtle starts at bottom left of bunker.
if you set door to 1 it will place the door 1 block to the right from where it started.
will not build the floor (if you want tell me in comment and i will add it.)
Pastebin: http://pastebin.com/qni0qx2r
Spoiler
params = {...}
length = tonumber(params[1])
width = tonumber(params[2])
height = tonumber(params[3])
door = tostring(params[4])
broadcast = true
currentSlot = 1
maxslots = 15
if broadcast then
rednet.open("right")
end
function fuel()
--Finds out if the turtle needs to refuel and if it has fuel to run
needsFuel = turtle.getFuelLevel()
hasFuel = turtle.getItemCount(16)
if needsFuel == "unlimited" then
else
if turtle.getFuelLevel() <= 10 then
if hasFuel > 0 then
turtle.select(16)
turtle.refuel(1)
turtle.select(currentSlot)
else
if broadcast then
rednet.broadcast( "Please refuel" )
end
print("Please insert fuel into slot 16")
repeat os.sleep(1)
until tonumber(turtle.getItemCount(16)) > 0
fuel()
end
end
end
end
function gotoNextSlotIfEmpty()
while turtle.getItemCount(currentSlot) == 0 do
currentSlot = currentSlot + 1
if currentSlot == maxslots+1 then
currentSlot = 1
if broadcast then
rednet.broadcast( "Please input new items" )
end
print("Please input new items in slot 1 to "..maxslots)
repeat os.sleep(1)
until tonumber(turtle.getItemCount(1)) > 0
end
turtle.select(currentSlot)
end
end
local function backHome(last)
if last then
for h=1,width-3 do
fuel()
turtle.back()
end
turtle.turnLeft()
else
turtle.turnRight()
end
for i=1,length-1 do
fuel()
turtle.back()
end
for j=1,height do
fuel()
turtle.down()
if j >= height-1 and door then
turtle.dig()
end
end
if door then
turtle.select(15)
turtle.place()
end
if broadcast then
rednet.broadcast( "Building finished" )
end
end
local function roof()
local turnRight = false
turtle.turnRight()
fuel()
turtle.forward()
for l = 1, length-2 do
for w = 1, width-2 do
turtle.placeDown()
gotoNextSlotIfEmpty()
if w ~= width-2 then
fuel()
turtle.forward()
end
end
if l ~= length-2 then
if turnRight then
turtle.turnRight()
fuel()
turtle.forward()
turtle.turnRight()
else
turtle.turnLeft()
fuel()
turtle.forward()
turtle.turnLeft()
end
end
turnRight = not turnRight
end
backHome(turnRight)
end
local function startbuilding()
if broadcast then
rednet.broadcast( "Building started" )
end
turtle.select(currentSlot)
fuel()
turtle.forward()
for h=1,height do
fuel()
turtle.up()
for i=1,2 do
for l=1,length do
turtle.placeDown()
gotoNextSlotIfEmpty()
fuel()
if l ~= length-1 then
turtle.forward()
end
end
turtle.placeDown()
gotoNextSlotIfEmpty()
fuel()
turtle.turnRight()
fuel()
turtle.forward()
for w=1,width-1 do
turtle.placeDown()
gotoNextSlotIfEmpty()
fuel()
if w ~= width-1 then
turtle.forward()
end
end
turtle.placeDown()
gotoNextSlotIfEmpty()
fuel()
turtle.turnRight()
fuel()
end
end
fuel()
turtle.forward()
roof()
end
function prime()
if (door == "1" or door == "yes" or door == "true" or door == true) and height >= 3 then
door = true
maxslots = 14
else
door = false
end
hasItem = turtle.getItemCount(1)
hasDoor = turtle.getItemCount(15)
if #params < 3 then
print("Usage: bunker <Length> <Width> <Height> <Door>")
else
if tonumber(hasItem) > 0 then
if door and tonumber(hasDoor) > 0 then
startbuilding()
elseif not door then
startbuilding()
else
print("Please put a door in slot 15")
repeat os.sleep(1)
until tonumber(turtle.getItemCount(15)) > 0
prime()
end
else
print("Please put "..(((length+width)*2)*height) + ((length-2)*(width-2)).." Blocks into slot 1-"..maxslots)
repeat os.sleep(1)
until tonumber(turtle.getItemCount(1)) > 0
prime()
end
end
end
prime()
Hope it helps somuone.comments are greatly appreciated