Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Controller script
- -- Seriously hacked from TurtleController-2.2.4
- -- -*-Lua-*-
- oldLabel=os.getComputerLabel()
- os.setComputerLabel("Remote Controller")
- print("")
- shell.run("id")
- print("")
- if peripheral.getType("right") == "modem" then
- rednet.open("right")
- elseif peripheral.getType("left") == "modem" then
- rednet.open("left")
- elseif peripheral.getType("top") == "modem" then
- rednet.open("top")
- elseif peripheral.getType("bottom") == "modem" then
- rednet.open("bottom")
- elseif peripheral.getType("back") == "modem" then
- rednet.open("back")
- elseif peripheral.getType("front") == "modem" then
- rednet.open("front")
- end
- print("What id would you like to connect to?")
- l=tonumber(read())
- print("")
- print("Type /list for a list of commands")
- print("")
- repeat
- write("Command : ")
- x=read()
- if x==("/list") then
- term.clear()
- term.setCursorPos(1,1)
- print("R --> refuel (This should work automatically)")
- print("f/l/b/r --> movement for/left/back/right")
- print("u/d/t --> up/down/turn around")
- print("sl/sr ---> step to the left/right and turn")
- print("sal/sar ---> step across to left/right")
- print("x/xu/xd --> dig ahead/up/down")
- print("p/pu/pd --> place ahead/up/down")
- -- print("tunnel --> dig 3x2") -- replaced by fp
- print("fp --> floorplace")
- print("a/au/ad --> attack/up/down")
- print("shutdown --> Shuts down transmitter and receiver")
- print("reboot --> reboots transmitter and receiver")
- print("stop --> Stops using this program")
- print("clear --> Clear Memory after picking up")
- print("AddCommand --> Allows you to add commands")
- elseif x==("AddCommand") then
- print("To set this up you have to go to your turtle")
- rednet.send(l,x)
- elseif x=="fp" then
- repeat
- print("how many blocks?")
- z = tonumber(read())
- until z >=1
- k=tostring(z)
- rednet.send(l,k)
- elseif x=="go" then
- print("remainder of command?")
- k = read()
- rednet.send(l,"go")
- sleep(0.1)
- rednet.send(l,k)
- else
- rednet.send(l,x)
- end
- -- now we listen for reply
- sleep(0.00000001)
- y,u=rednet.receive(l)
- print("Received ",u," from ",y)
- if u==("p2") and y==l then
- print("Out of coal and fuel")
- end
- if u==("s") and y==l then
- print("Stopping and shutdown remote")
- print("Stopping local program")
- end
- if u==("p") and y==l then
- print("Incorrect Command")
- elseif u==("Matches") and y==l then
- end
- print("Command Correct")
- until
- x==("clear") or x==("stop")
- if x==("clear") then
- os.setComputerLabel(oldLabel)
- end
- -- end of controller script --
- -- -*-Lua-*-
- -- Turtle script
- -- Seriously hacked from TurtleController-2.2.4
- if turtle then
- print[[---------------------------------------------------
- Welcome to RemoteTurtle V2.2.4
- ---------------------------------------------------
- ]]
- end
- -- excerpted from CC:Tweaked
- local function tokenise(...)
- local sLine = table.concat({ ... }, " ")
- local tWords = {}
- local bQuoted = false
- for match in string.gmatch(sLine .. "\"", "(.-)\"") do
- if bQuoted then
- table.insert(tWords, match)
- else
- for m in string.gmatch(match, "[^ \t]+") do
- table.insert(tWords, m)
- end
- end
- bQuoted = not bQuoted
- end
- return tWords
- end
- os.setComputerLabel("Remote Turtle")
- print("")
- shell.run("id")
- rednet.open("right")
- print("")
- print("Id To Receive commands from?")
- l=tonumber(read())
- repeat
- i,k=rednet.receive()
- z=turtle.getFuelLevel()
- if
- z==0 then
- shell.run("refuel", "all")
- turtle.select(1)
- end
- z=turtle.getFuelLevel()
- if
- z==0 then
- rednet.send(l,"p2")
- end
- if
- l==i and k==("tunnel") then
- -- send back "continue"
- print("Received tunnel, waiting for number")
- i,k=rednet.receive()
- -- needs to be a number - will fall over otherwise
- print("Received ",k," from ", i)
- g=tonumber(k)
- if l==i and g>0 then
- -- do the tunnel 3x2
- -- abc
- -- def
- for m=1,g do
- turtle.attack() --clear first block e
- turtle.forward() -- e
- turtle.attackUp() -- eb
- turtle.turnLeft()
- turtle.attack() -- ed
- turtle.forward() -- d
- turtle.attackUp() -- da
- turtle.back() -- e
- turtle.turnRight()
- turtle.turnRight()
- turtle.attack() -- ef
- turtle.forward() -- f
- turtle.attackUp() -- fc
- turtle.back() -- e
- turtle.turnLeft()
- end
- else -- g ~= number
- print("Incorrect message format")
- sleep(0.2)
- rednet.send(l,"p")
- end
- elseif
- l==i and k==("go") then
- sleep(0.1)
- i,k=rednet.receive()
- g=tokenise(k)
- print("Got back ",g," from ",i)
- shell.run("go", unpack(g))
- elseif
- l==i and k==("R") then
- shell.run("refuel")
- elseif
- l==i and k==("f") then
- turtle.forward()
- elseif
- l==i and k==("b") then
- turtle.back()
- elseif
- l==i and k==("l") then
- turtle.turnLeft()
- elseif
- l==i and k==("r") then
- turtle.turnRight()
- elseif
- l==i and k==("u") then
- turtle.up()
- elseif
- l==i and k==("d") then
- turtle.down()
- elseif
- l==i and k==("t") then
- turtle.turnRight()
- turtle.turnRight()
- elseif
- l==i and k==("sl") then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- elseif
- l==i and k==("sr") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- elseif
- l==i and k==("sal") then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- elseif
- l==i and k==("sar") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- elseif
- l==i and k==("x") then
- turtle.dig()
- elseif
- l==i and k==("xu") then
- turtle.digUp()
- elseif
- l==i and k==("xd") then
- turtle.digDown()
- elseif
- l==i and k==("p") then
- turtle.place()
- elseif
- l==i and k==("pu") then
- turtle.placeUp()
- elseif
- l==i and k==("pd") then
- turtle.placeDown()
- elseif
- l==i and k==("slot") then
- turtle.select(1)
- elseif
- l==i and tonumber(k)~=nil then
- print("floorplace ",k)
- shell.run("floorplace",k) -- should place floors for k blocks
- elseif
- l==i and k==("clear") then
- os.setComputerLabel("")
- elseif
- l==i and k==("a") then
- turtle.attack()
- elseif
- l==i and k==("au") then
- turtle.attackUp()
- elseif
- l==i and k==("ad") then
- turtle.attackDown()
- elseif
- l==i and k==("reboot") then
- os.reboot()
- elseif
- l==i and k==("shutdown") then
- os.shutdown()
- elseif
- l==i and k==("stop") then
- print("Stopping program")
- rednet.send(l,"s")
- sleep(0.1)
- os.shutdown()
- elseif
- l==i and k==(cmd1) then
- turtle[cmd1e]()
- elseif
- l==i and k==(cmd2) then
- turtle[cmd2e]()
- elseif
- l==i and k==(cmd3) then
- turtle[cmd3e]()
- elseif
- l==i and k==("AddCommand") then
- print("Which command do you want to change? 1/2/3")
- cwhat=read()
- print("for the question :What do you want to execute? you answer has to be what would fill in the blank spot: turtle.[BLANK SPOT]()")
- if cwhat == ("1") then
- print("What do you want to type to to execute")
- cmd1=read()
- print("What do you want to execute?")
- cmd1e=read()
- elseif
- chwat == ("2") then
- print("What do you want to type to execute?")
- cmd2=read()
- print("What do you want to execute?")
- cmd2e=read()
- elseif
- chwat == ("3") then
- print("What do you want to type to execute?")
- cmd3=read()
- print("What do you want to execute?")
- cmd3e=read()
- end
- else
- sleep(0.2)
- print("Doesn't match")
- rednet.send(l,"p")
- end
- sleep(0.2)
- rednet.send(l,"Matches")
- until
- l==i and k==("stop") or l==i and k==("clear")
- -- end of turtle script --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement