Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clients = {}
- local modem = peripheral.find("modem")
- rednet.open("back")
- HUBID = os.getComputerID()
- print("HUB Computer ID: "..HUBID)
- local command = nil
- function remoteControl()
- io.write("Select a turtle to Control: ")
- slave = tonumber(read())
- rednet.send(slave, "rcConnect", rc)
- while true do
- local event, key, isHeld = os.pullEvent("key")
- if key == keys.w then
- rednet.send(slave, "forward")
- elseif key == keys.s then
- rednet.send(slave, "backward")
- elseif key == keys.a then
- rednet.send(slave, "left")
- elseif key == keys.d then
- rednet.send(slave, "right")
- elseif key == keys.q then
- rednet.send(slave, "up")
- elseif key == keys.e then
- rednet.send(slave, "down")
- elseif key == keys.numPad5 then
- rednet.send(slave, "dig")
- elseif key == keys.numPad8 then
- rednet.send(slave, "digUp")
- elseif key == keys.numPad2 then
- rednet.send(slave, "digDown")
- elseif key == keys.insert then
- rednet.send(slave, "place")
- elseif key == keys.up then
- rednet.send(slave, "placeUp")
- elseif key == keys.down then
- rednet.send(slave, "placeDown")
- elseif key == keys.right then
- rednet.send(slave, "slotNext")
- elseif key == keys.left then
- rednet.send(slave, "slotPrev")
- elseif key == keys.home then
- rednet.send(slave, "rcDisc")
- print("Connection from "..slave.." terminated.")
- break
- end
- end
- end
- function list()
- for i,v in ipairs(clients) do
- print("ID "..v)
- end
- end
- function newConnection()
- event, sender, message, protocol = os.pullEvent("rednet_message")
- if message == "connectMsg" then
- table.insert(clients, sender)
- print(sender.." has connected.")
- rednet.send(sender, "connectSuccess", connect)
- end
- end
- function userInput()
- command = io.read()
- end
- while true do
- parallel.waitForAny(newConnection,userInput)
- if command == "list" then
- if #clients == 0 then
- print("No connections found.")
- else
- list()
- command = nil
- end
- end
- if command == "RC" then
- remoteControl()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement