Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local index = 1
- turtle.select(1)
- function place()
- while turtle.detectUp() do
- turtle.digUp()
- end
- turtle.digDown()
- turtle.placeDown()
- if turtle.getItemCount(index) == 0 then
- index = index + 1
- end
- if index > 16 then
- index = 1
- end
- turtle.select(index)
- end
- function removeFence(length,width)
- turtle.digDown()
- for i = 1, 4 do
- if i==1 or i==3 then
- side=length
- else
- side=width
- end
- for j = 1, side-1 do
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- end
- turtle.turnRight()
- end
- end
- function buildFence(length,width)
- place()
- for i = 1, 4 do
- if i==1 or i==3 then
- side=length
- else
- side=width
- end
- for j = 1, side-1 do
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- place()
- end
- turtle.turnRight() -- Goes clockwise
- end
- end
- function myName()
- fullName = shell.getRunningProgram()
- return fs.getName(fullName)
- end
- function mats()
- count=0
- for i=1,16 do
- count = count + turtle.getItemCount(i)
- end
- return count
- end
- function needed(length,width)
- return (length*2)+(width*2)
- end
- args = {...}
- if #args < 3 then
- print("Usage:")
- print(" "..myName().." <length> <width> <remove|build>")
- print(" Turtle should also contain materials to be used as fences, preferably fences.")
- return
- end
- if tonumber(args[1])==nil or tonumber(args[2])==nil then
- print("Dimensions must be numerical.")
- return
- end
- if tonumber(args[1]) < 1 or tonumber(args[2]) < 1 then
- print("A dimension may not be less than 1")
- return
- end
- if mats() < needed(tonumber(args[1]),tonumber(args[2])) then
- print("Not enough materials in turtle to build fence, please add more materials.")
- return
- end
- if args[3]== "remove" then
- removeFence(tonumber(args[1]),tonumber(args[2]))
- elseif args[3]=="build" then
- buildFence(tonumber(args[1]),tonumber(args[2]))
- else
- print("The third option must be either 'remove' or 'build'")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement