Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - --
 - -- Solar Panel Placer v1.1 by Joseph Jones
 - --
 - -- Instructions found at: http://www.computercraft.info/forums2/index.php?/topic/13942-solar-panel-placer/
 - --
 - -- Needs solar panels. Uses slots 1-8
 - -- Needs cables. Uses slots 9-15
 - -- Needs fuel. Uses slot 16
 - --
 - -- ChangeLog:
 - -- July 6, 2013: [v1.0] Finished initial release.
 - -- July 7, 2013: [v1.1] More efficient when placing flowers.
 - --
 - local solarPanelSlot
 - local cableSlot
 - function checkFuel()
 - if(turtle.getFuelLevel() < 2) then
 - turtle.select(16)
 - if(turtle.refuel(1)==false) then
 - print("Turtle needs more fuel in slot 16. Press enter to continue")
 - io.read()
 - checkFuel()
 - end
 - end
 - end
 - function move()
 - checkFuel()
 - while(turtle.forward()==false)do turtle.dig() end
 - end
 - function moveBack()
 - checkFuel()
 - while(turtle.back()==false)do end
 - end
 - function moveUp()
 - checkFuel()
 - while(turtle.up()==false)do turtle.digUp() end
 - end
 - function moveDown()
 - checkFuel()
 - while(turtle.down()==false)do turtle.digDown() end
 - end
 - --This places a solar panel in a specified direction
 - --Direction: 2 is down, 1 is up, 0 is in front
 - function placeSolarPanel(direction)
 - local lastSlot = solarPanelSlot
 - while(turtle.getItemCount(solarPanelSlot)==0)do
 - solarPanelSlot = solarPanelSlot+1
 - if(solarPanelSlot == 9) then
 - solarPanelSlot = 1
 - end
 - if(solarPanelSlot == lastSlot) then
 - print("Turtle needs more solar panels in slots 1-8.")
 - print("Press enter to continue")
 - io.read()
 - end
 - end
 - turtle.select(solarPanelSlot)
 - if direction==1 then
 - while(turtle.placeUp()==false) do turtle.digUp() end
 - else if direction ==2 then
 - while(turtle.placeDown()==false) do turtle.digDown() end
 - else
 - while(turtle.place()==false) do turtle.dig() end
 - end end
 - end
 - --This places a cable in a specified direction
 - --Direction: 2 is down, 0 is in front
 - function placeCable(direction)
 - local lastSlot = cableSlot
 - while(turtle.getItemCount(cableSlot)==0)do
 - cableSlot = cableSlot+1
 - if(cableSlot == 16) then
 - cableSlot = 9
 - end
 - if(cableSlot == lastSlot) then
 - print("Turtle needs more cables in slots 9-15.")
 - print("Press enter to continue")
 - io.read()
 - end
 - end
 - turtle.select(cableSlot)
 - if(direction==2) then
 - while(turtle.placeDown()==false) do turtle.digDown() end
 - else
 - while(turtle.place()==false) do turtle.dig() end
 - end
 - end
 - function clearRow(length, digUp)
 - for tempLength = length, 1, -1 do
 - move()
 - if digUp then
 - turtle.digUp()
 - end
 - end
 - end
 - function placeSolarRow(length)
 - clearRow(length)
 - for tempLength = length, 1, -1 do
 - moveBack()
 - placeSolarPanel(0)
 - end
 - end
 - function placeCableAndSolarRow(length)
 - clearRow(length,true)
 - for tempLength = length, 1, -1 do
 - placeSolarPanel(1)
 - moveBack()
 - placeCable(0)
 - end
 - end
 - function goToNextRow()
 - turtle.turnRight()
 - move()
 - turtle.turnLeft()
 - end
 - function goUpToNextRow()
 - goToNextRow()
 - moveUp()
 - moveUp()
 - end
 - function goDownToNextRow()
 - goToNextRow()
 - moveDown()
 - moveDown()
 - end
 - function placeGable(length, height)
 - state = true
 - --This handles the left half of the gable
 - for tl = height-1, 1, -1 do
 - if state then
 - if(tl~=height-1) then goUpToNextRow() end
 - placeSolarRow(length)
 - else
 - goToNextRow()
 - placeCableAndSolarRow(length)
 - end
 - state = state==false
 - end
 - --This handles the middle row of the gable
 - --Different depending on if the height is even or odd.
 - goToNextRow()
 - if(height%2==1) then moveUp() end
 - placeCableAndSolarRow(length)
 - goToNextRow()
 - if(height%2==1) then moveDown() end
 - state = state==false
 - --This handles the right half of the gable
 - for tl = height-1, 1, -1 do
 - if state then
 - if(tl~=height-1) then goToNextRow() end
 - placeSolarRow(length)
 - else
 - if(tl~=height-1) then goDownToNextRow() end
 - placeCableAndSolarRow(length)
 - end
 - state = state==false
 - end
 - end
 - function placeLastFlowerRows()
 - moveUp()
 - placeSolarPanel(2)
 - move()
 - placeCable(2)
 - move()
 - placeSolarPanel(2)
 - moveBack()
 - turtle.turnRight()
 - move()
 - placeSolarPanel(2)
 - moveBack()
 - moveBack()
 - placeSolarPanel(2)
 - move()
 - moveUp()
 - placeSolarPanel(2)
 - end
 - function placeFlower(height)
 - if(height==2) then
 - placeLastFlowerRows()
 - return
 - end
 - for section=4, 1, -1 do
 - move()
 - placeSolarPanel(2)
 - turtle.turnLeft()
 - move()
 - placeCable(2)
 - turtle.turnRight()
 - move()
 - placeSolarPanel(2)
 - moveBack()
 - turtle.turnLeft()
 - for spib = height - 3, 1, -1 do
 - move()
 - placeSolarPanel(2)
 - turtle.turnLeft()
 - move()
 - placeCable(2)
 - move()
 - placeCable(2)
 - if(section~= 1 or spib ~= 1) then
 - moveBack()
 - turtle.turnRight()
 - end
 - end
 - end
 - if(height==3) then
 - turtle.turnLeft()
 - move()
 - placeCable(2)
 - moveBack()
 - else
 - --moveBack()
 - --moveBack(
 - moveUp()
 - end
 - placeFlower(height-1)
 - end
 - function main()
 - solarPanelSlot = 1
 - cableSlot = 9
 - local length
 - local height
 - print("Type in the number of the style you wish to build.")
 - print("")
 - print("1.) Flower")
 - print("2.) Gable (Triangular Roof)")
 - --Gets sytle for building and checks input
 - local input = tonumber(io.read())
 - while(input~=1 and input ~= 2) do
 - print("Invalid choice. The number must be between 1-2.")
 - input = tonumber(io.read())
 - end
 - --Gets the length for the gable and checks input
 - if input == 2 then
 - print()
 - print("Length?")
 - length = tonumber(io.read())
 - while length<0 do
 - print("The length cannot be less than zero")
 - length = tonumber(io.read())
 - end
 - end
 - --Gets the hieght and checks input
 - print()
 - print("Height?")
 - height = tonumber(io.read())
 - while height<2 do
 - print("The height cannot be less than two")
 - height = tonumber(io.read())
 - end
 - --places the gable
 - if input == 2 then
 - placeGable(length, height)
 - else
 - if height==2 then
 - placeLastFlowerRows()
 - return
 - end
 - --Gets to the initial height needed for 3 layers or more.
 - moveUp()
 - move()
 - move()
 - turtle.turnLeft()
 - move()
 - turtle.turnLeft()
 - placeFlower(height)
 - end
 - end
 - main()
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment