Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- peripheral.find("modem", rednet.open)
- local turtleNeighbor = peripheral.find("turtle")
- term.clear()
- term.setCursorPos(1, 1)
- if turtleNeighbor then
- print("Turning on neighbor turtle")
- turtleNeighbor.turnOn()
- end
- print("Running Turtle Control Reciever\n")
- os.setComputerLabel(tostring(os.getComputerID()))
- local usedPastes = {
- { "YYizkd25", "tunnel.lua" },
- { "dHn1pbtb", "miner.lua" },
- { "aPfiecwi", "bridge.lua" },
- { "AmKU7gZV", "lavafuel.lua" },
- { "Rvu21mX6", "drain.lua" },
- { "wjrXLHvw", "startup.lua" }
- }
- local function Split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t = {}
- for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
- table.insert(t, str)
- end
- return t
- end
- local function DownloadPastebins(update)
- local downloaded = {}
- for i, paste in pairs(usedPastes) do
- local pid, ppath = paste[1], paste[2]
- if update then
- if fs.exists(ppath) then
- fs.delete(ppath)
- end
- end
- if not fs.exists(ppath) then
- table.insert(downloaded, ppath)
- shell.run("pastebin", "get", pid, ppath)
- term.clear()
- term.setCursorPos(1, 1)
- for i, p in pairs(downloaded) do
- print("Downloading " .. p)
- end
- end
- end
- if #downloaded > 0 then
- print("Done downloading!")
- end
- for i, pname in pairs(downloaded) do
- if pname == "startup.lua" then
- print("Restarting new startup.lua")
- shell.run("startup.lua")
- break
- end
- end
- end
- local function RunProgram(path, args)
- if not fs.exists(path) then
- print("missing program!")
- print("reinstalling program...")
- DownloadPastebins()
- print("done installing!")
- end
- table.remove(args, 1)
- shell.run(path, table.unpack(args))
- end
- DownloadPastebins(false)
- while true do
- local id, message, protocol = rednet.receive()
- local args = Split(message)
- if args[1] == "go" then
- local moveFunc = nil
- if args[2] == "up" then
- moveFunc = turtle.up
- elseif args[2] == "forward" then
- moveFunc = function()
- local attempts = 0
- local hasBlock, data = turtle.inspect()
- if hasBlock then
- if data.name == "computercraft:turtle_normal" then
- repeat
- local success = turtle.forward()
- attempts = attempts + 1
- until success or attempts > 50
- end
- else
- turtle.forward()
- end
- end
- elseif args[2] == "back" then
- moveFunc = function()
- local attempts = 0
- repeat
- local success = turtle.back()
- attempts = attempts + 1
- until success or attempts > 100
- end
- elseif args[2] == "left" then
- moveFunc = turtle.turnLeft
- elseif args[2] == "right" then
- moveFunc = turtle.turnRight
- elseif args[2] == "down" then
- moveFunc = turtle.down
- end
- for i = 1, tonumber(args[3]) or 1 do
- pcall(moveFunc)
- end
- elseif args[1] == "dig" then
- if args[2] == "up" then
- turtle.digUp()
- elseif args[2] == "down" then
- turtle.digDown()
- else
- turtle.dig()
- end
- elseif args[1] == "place" then
- if args[2] == "up" then
- turtle.placeUp()
- elseif args[2] == "down" then
- turtle.placeDown()
- else
- turtle.place()
- end
- elseif args[1] == "drop" then
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local data = turtle.getItemDetail()
- if args[2] == nil or data.name == args[2] then
- turtle.drop(64)
- end
- end
- end
- turtle.select(1)
- elseif args[1] == "miner" then
- RunProgram("miner.lua", args)
- elseif args[1] == "tunnel" then
- RunProgram("tunnel.lua", args)
- elseif args[1] == "bridge" then
- RunProgram("bridge.lua", args)
- elseif args[1] == "lavafuel" then
- RunProgram("lavafuel.lua", args)
- elseif args[1] == "drain" then
- RunProgram("drain.lua", args)
- elseif args[1] == "update" then
- DownloadPastebins(true)
- elseif args[1] == "refuel" then
- shell.run("refuel", "all")
- elseif args[1] == "reboot" then
- shell.run("reboot")
- elseif args[1] == "shutdown" then
- peripheral.find("modem", rednet.close)
- shell.run("shutdown")
- elseif args[1] == "select" then
- turtle.select(tonumber(args[2] or turtle.getSelectedSlot()))
- elseif args[1] == "dance" then
- shell.run("dance")
- end
- end
Add Comment
Please, Sign In to add comment