Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- if peripheral.isPresent("left") then
- m= peripheral.wrap("left")
- m.turnOn()
- end
- if peripheral.isPresent("top") then
- m= peripheral.wrap("top")
- m.turnOn()
- end
- if peripheral.isPresent("back") then
- m= peripheral.wrap("back")
- m.turnOn()
- end
- if peripheral.isPresent("front") then
- m= peripheral.wrap("front")
- m.turnOn()
- end
- if peripheral.isPresent("bottom") then
- m= peripheral.wrap("bottom")
- m.turnOn()
- end
- function dig(side)
- if side == "front" then
- if turtle.detect() == true then
- rs.setOutput("front", false)
- while rs.getInput(side) do
- sleep(0.2)
- end
- end
- elseif side == "down" then
- if turtle.detectDown() == true then
- rs.setOutput("bottom", false)
- while rs.getInput("bottom") do
- sleep(0.2)
- end
- rs.setOutput("bottom", true)
- end
- elseif side == "up" then
- if turtle.detectUp() == true then
- rs.setOutput("top", false)
- while rs.getInput("top") do
- sleep(0.2)
- end
- end
- end
- print("Block in the way, digging!")
- if side == "front" then
- turtle.dig()
- elseif side == "down" then
- turtle.digDown()
- elseif side == "up" then
- turtle.digUp()
- end
- end
- function docmd(aaction, adir, ax)
- if aaction == "mv" then
- print("Action: mv")
- i = 0
- while i<ax do
- print("Action done"..tostring(i).."/"..tostring(ax).." times")
- print("Direction "..tostring(adir))
- if adir == "f" then
- while rs.getInput("front") == true do
- a = 0 -- Do NOTHING
- end
- dig("front")
- elseif adir == "u" then
- while rs.getInput("top") == true do
- a = 0 -- Do NOTHING
- end
- dig("up")
- elseif adir == "d" then
- while rs.getInput("bottom") == true do
- a = 0 -- Do NOTHING
- end
- dig("down")
- end
- if adir == "f" then
- turtle.forward()
- elseif adir == "b" then
- turtle.back()
- elseif adir == "u" then
- turtle.up()
- elseif adir == "d" then
- turtle.down()
- else
- print("Unknown direction!")
- end
- i = i + 1
- rs.setOutput("front", true)
- rs.setOutput("back", true)
- rs.setOutput("right", true)
- rs.setOutput("left", true)
- rs.setOutput("bottom", true)
- rs.setOutput("top", true)
- end
- elseif aaction == "select" then
- turtle.select(x)
- end
- end
- dir = "f"
- x = 0
- action = ""
- max = 17
- -- 1 = forward
- -- 2 = back
- -- 3 = up
- -- 4 = down
- rednet.open("right")
- shell.run("label set RCTurtleSlave")
- while 1<2 do
- dir = 0
- x = 0
- action = ""
- print("Waiting for cmd")
- dist = "N/A"
- id, msg = rednet.receive()
- print("ID "..id..", "..dist.." blocks away said "..msg..".")
- msg2 = msg
- if msg:sub(1,7) == "forward" then
- action = "mv"
- dir = "f"
- x = tonumber(msg2:sub(8,11))
- elseif msg:sub(1,2) == "up" then
- action = "mv"
- dir = "u"
- x = tonumber(msg2:sub(3,5))
- elseif msg:sub(1,4) == "down" then
- action = "mv"
- dir = "d"
- x = tonumber(msg2:sub(5,8))
- elseif msg:sub(1,4) == "back" then
- action = "mv"
- dir = "b"
- x = tonumber(msg2:sub(5,8))
- elseif msg:sub(1,6) == "select" then
- action = "select"
- dir = "dasjndkjfn"
- x = tonumber(msg2:sub(7,8))
- elseif msg == "ud" then
- shell.run("pastebin get HVArpJ7c ud")
- shell.run("ud")
- elseif msg == "dig" then
- turtle.dig()
- elseif msg == "drop" then
- turtle.drop()
- elseif msg == "dropdown" then
- turtle.dropDown()
- elseif msg == "dropup" then
- turtle.dropUp()
- elseif msg == "empty" then
- i = 1
- while i<max do
- turtle.select(i)
- turtle.drop(i)
- i = i + 1
- end
- elseif msg == "emptydown" then
- i = 1
- while i<max do
- turtle.select(i)
- turtle.dropDown(i)
- i = i + 1
- end
- elseif msg == "suck" then
- turtle.suck()
- elseif msg == "tr" then
- turtle.turnRight()
- elseif msg == "tl" then
- turtle.turnLeft()
- elseif msg == "ping" then
- print("Command: ping")
- rednet.broadcast("TPong")
- print("Sent a TPong")
- else
- print("Unknown cmd")
- end
- docmd(action, dir, x)
- end
Advertisement
Add Comment
Please, Sign In to add comment