Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------
- -- basic functions for turtle control -
- ---------------------------------------
- --Make external function to be copied to multiple turtles--
- local function gf() while not turtle.forward() do end end
- local function gb() while not turtle.back() do end end
- local function gu() while not turtle.up() do end end
- local function gd() while not turtle.down() do end end
- local function gl() while not turtle.turnLeft() do end end
- local function gr() while not turtle.turnRight() do end end
- local function df() turtle.dig() end
- local function du() turtle.digUp() end
- local function dd() turtle.digDown() end
- local function pf() turtle.place() end
- local function pu() turtle.placeUp() end
- local function pd() turtle.placeDown() end
- local function sf() turtle.suck() end
- local function su() turtle.suckUp() end
- local function sd() turtle.suckDown() end
- local function Df() turtle.drop() end
- local function Du() turtle.dropUp() end
- local function Dd() turtle.dropDown() end
- local function ss(s) turtle.select(s) end
- --function to suck and drop all from chest--
- function suckAll()
- ss(1) sf() ss(2) sf() ss(3) sf() ss(4) sf() ss(5) sf() ss(6)
- sf() ss(7) sf() ss(8) sf() ss(9) sf()
- end
- function dropAll()
- ss(1) Df() ss(2) Df() ss(3) Df() ss(4) Df() ss(5) Df() ss(6)
- Df() ss(7) Df() ss(8) Df() ss(9) Df()
- end
- -- start rednet, broadcast online and check fuel --
- rednet.open("left")
- rednet.broadcast(os.computerID().. " Butler is online!")
- function clear() term.clear() term.setCursorPos(1, 1) end
- local minFuelAmount = 100
- while true do
- rednet.open("left")
- clear()
- if turtle.getFuelLevel() < minFuelAmount then
- print("I am out of fuel!")
- rednet.broadcast("The butler is out of fuel!")
- ss(16)
- turtle.refuel(1)
- end
- print( "ID: [", os.computerID(), "]Butler is waiting for insturctions.")
- rednet.send(62, "Listening")
- local id, msg = rednet.receive(5)
- if msg == "deposit gold" then
- print("Told to deposit gold by ID:["..id.."]")
- shell.run("goto", -64,66,-444)
- suckAll()
- gl() gl()
- shell.run("goto", -67,67,-447)
- dropAll()
- gl() gl() gf()
- else
- if msg == "withdraw gold" then
- local id, msg = rednet.receive()
- amount = tonumber(msg)
- print("Told to retrieve gold by ID:["..id.."]")
- shell.run("goto", -67,67,-447)
- turtle.suck(amount)
- shell.run("goto", -62,66,-444)
- dropAll()
- gl() gl() gf()
- else
- if msg == "deposit iron" then
- print("Told to deposit iron by ID:["..id.."]")
- shell.run("goto", -64,66,-444)
- suckAll()
- gl() gl()
- shell.run("goto", -67,66,-447)
- dropAll()
- gl() gl() gf()
- else
- if msg == "withdraw iron" then
- local id, msg = rednet.receive()
- amount = tonumber(msg)
- print("Told to retrieve iron by ID:["..id.."]")
- shell.run("goto", -67,66,-447)
- turtle.suck(amount)
- shell.run("goto", -62,66,-444)
- dropAll()
- gl() gl() gf()
- else
- if msg == "deposit diamond" then
- print("Told to deposit iron by ID:["..id.."]")
- shell.run("goto", -64,66,-444)
- suckAll()
- gl() gl()
- shell.run("goto", -67,65,-447)
- dropAll()
- gl() gl() gf()
- else
- if msg == "withdraw diamond" then
- local id, msg = rednet.receive()
- amount = tonumber(msg)
- print("Told to retrieve iron by ID:["..id.."]")
- gu()
- shell.run("goto", -67,65,-447)
- turtle.suck(amount)
- shell.run("goto", -62,66,-444)
- dropAll()
- gl() gl() gf()
- if msg == "reboot" then
- os.reboot()
- else
- if msg =="update" then
- rednet.broadcast("Butler is updating")
- shell.run("update")
- return
- end
- end
- end
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement