Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------
- -------- GLOBAL VARIABLES --------
- ---------------------------------------
- height = 0
- ---------------------------------------
- -- BASIC FUNCTIONS FOR TURTLE CONTROL -
- ---------------------------------------
- local function gf(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.forward()
- end
- end
- local function gb(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.back()
- end
- end
- local function gu(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.up()
- end
- end
- local function gd(n)
- if n==nil then
- n=1
- end
- for i=1,n,1 do
- turtle.down()
- end
- end
- local function tl()
- turtle.turnLeft()
- end
- local function tr()
- turtle.turnRight()
- end
- local function pf() turtle.place() end
- local function pu() turtle.placeUp() end
- local function pd() turtle.placeDown() end
- local function df() return turtle.dig() end
- local function du() turtle.digUp() end
- local function dd() turtle.digDown() end
- local function sf() turtle.suck() end
- local function su(n)
- if n==nil then
- while turtle.suckUp() do end
- else
- for i=1,n do
- turtle.suckUp()
- end
- end
- end
- local function sd(n)
- if n==nil then
- while turtle.suckDown() do end
- else
- for i=1,n do
- turtle.suckDown()
- end
- end
- end
- local function Df() turtle.drop() end
- local function Du() turtle.dropUp() end
- local function Dd(n)
- if n==nil then n=64 end
- turtle.dropDown(n)
- end
- local function ss(s) turtle.select(s) end
- local function cf() turtle.compare() end
- local function cu() turtle.compareUp() end
- ---------------------------------------
- -- BUILDING BLOCKS --
- ---------------------------------------
- function messageHandler()
- local event, senderId, message, protocol = os.pullEvent("rednet_message")
- if protocol ~= "worker" then
- return
- elseif message == "location" then
- print("Sending location to ID#"..tostring(senderId))
- sendLocation(senderId)
- elseif message == "dig" then
- rednet.send(senderId,"Digging...","home")
- print("Digging...")
- clearArea(4,4)
- elseif message == "reboot" then
- rednet.send(senderId,"Rebooting...","home")
- shell.run("reboot")
- else
- print("Invalid message:"..message)
- end
- end
- function sendLocation(host)
- local x, y, z = gps.locate()
- --print("ID:" .. homeid)
- local message = tostring(x) .. " " .. tostring(y) .. " " .. tostring(z)
- rednet.send(host,message,"home")
- end
- function digColumn()
- local height = 0
- while turtle.inspect() do
- df()
- end
- gf()
- while turtle.inspectUp() do
- while turtle.inspectUp() do
- du()
- end
- gu()
- height = height + 1
- end
- while height > 0 do
- gd()
- height = height - 1
- end
- end
- function clearArea(length, width)
- local x1,y1,z1 = gps.locate()
- local x2,y2,z2 = x1,y1,z1
- digColumn()
- x2,y2,z2 = gps.locate()
- end
- ---------------------------------------
- -- MAIN PROGRAM --
- ---------------------------------------
- print("Starting main...")
- --Register for Rednet
- rednet.host("worker","ana")
- rednet.open("right")
- --clearArea(4,4)
- --while true do
- --messageHandler()
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement