SHOW:
|
|
- or go back to the newest paste.
| 1 | local modem = peripheral.wrap("left")
| |
| 2 | rednet.open("left")
| |
| 3 | print("Waiting for papa...")
| |
| 4 | local papa = "" | |
| 5 | local id = "" | |
| 6 | repeat | |
| 7 | local senderId, message, protocol = rednet.receive() | |
| 8 | papa = senderId | |
| 9 | id = senderId | |
| 10 | until (message == "pair") and (protocol == "tmzst") | |
| 11 | print("get request from "..id)
| |
| 12 | rednet.send(papa,os.getComputerID(),"tmzst") | |
| 13 | papa = senderId | |
| 14 | local function receive() | |
| 15 | while true do | |
| 16 | local senderId, ms, protocol = rednet.receive() | |
| 17 | print(ms) | |
| 18 | if (senderId == id) and (protocol == "tmzst") then | |
| 19 | if ms == "w" then | |
| 20 | print("fw")
| |
| 21 | turtle.forward() | |
| 22 | elseif ms == "s" then | |
| 23 | turtle.back() | |
| 24 | elseif ms == "a" then | |
| 25 | turtle.turnLeft() | |
| 26 | elseif ms == "d" then | |
| 27 | turtle.turnRight() | |
| 28 | elseif ms == "shift" then | |
| 29 | turtle.up() | |
| 30 | elseif ms == "ctrl" then | |
| 31 | turtle.down() | |
| 32 | elseif ms == "e" then | |
| 33 | turtle.dig() | |
| 34 | elseif ms == "q" then | |
| 35 | turtle.select(2) | |
| 36 | turtle.place() | |
| 37 | turtle.select(1) | |
| 38 | elseif ms == "r" then | |
| 39 | repeat | |
| 40 | turtle.forward() | |
| 41 | local senderId, msg, protocol = rednet.receive("tmzst",1)
| |
| 42 | until msg == "r" | |
| 43 | end | |
| 44 | end | |
| 45 | - | rednet.send(id,turtle.getFuelLevel(),"tmzst") |
| 45 | + | |
| 46 | end | |
| 47 | local function send() | |
| 48 | while true do | |
| 49 | sleep(1) | |
| 50 | rednet.send(id,turtle.getFuelLevel(),"tmzstf") | |
| 51 | turtle.refuel() | |
| 52 | end | |
| 53 | end | |
| 54 | parallel.waitForAll(send,receive) |