Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Source: http://adf.ly/mQGKM
- Authors: Lyqyd, Zaflis, Kreezxil
- Ripped by: Kreezxil
- Notes: Until now this code sat freely in forum, its still free, but now its encapsulated in a program that can be run and given arguments as well as loaded with 'pastebin get'
- Changelog:
- 2/22/14 - Requested Concept by Narny123 - http://adf.ly/mQFxT
- 2/22/14 - Original Code by Lyqyd - http://adf.ly/mQG5h
- 2/28/14 - Modified Code by Zaflis - http://adf.ly/mQGD2
- - now supports digging through gravel, and digs high enough tunnel for player to follow through
- - added code to allow fence removal
- 5/10/14 - Modified Code by Kreezxil
- - rearranged and encapsulated with function declarations parts of code to allow it to be in a program much easier
- - added arguments for variable sized fence building and removing
- - added help when arguments fail to match or nothing slot 1
- --]]
- 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
Add Comment
Please, Sign In to add comment