Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("left")
- rednet.open("left")
- local speaker = peripheral.find("speaker")
- local dfpwm = require("cc.audio.dfpwm")
- function playMusic(name)
- local decoder = dfpwm.make_decoder()
- for chunk in io.lines(name 16 * 1024) do
- local buffer = decoder(chunk)
- while not speaker.playAudio(buffer) do
- os.pullEvent("speaker_audio_empty")
- end
- end
- end
- print("Waiting for papa...")
- local papa = ""
- local id = ""
- repeat
- local senderId, message, protocol = rednet.receive()
- papa = senderId
- id = senderId
- until (message == "pair") and (protocol == "tmzst")
- print("get request from "..id)
- rednet.send(papa,os.getComputerID(),"tmzst")
- papa = senderId
- local function receive()
- while true do
- local senderId, ms, protocol = rednet.receive()
- print(ms)
- if (senderId == id) and (protocol == "tmzst") then
- if ms == "w" then
- print("fw")
- turtle.forward()
- elseif ms == "s" then
- turtle.back()
- elseif ms == "a" then
- turtle.turnLeft()
- elseif ms == "d" then
- turtle.turnRight()
- elseif ms == "shift" then
- turtle.up()
- elseif ms == "ctrl" then
- turtle.down()
- elseif ms == "e" then
- turtle.dig()
- elseif ms == "q" then
- turtle.select(2)
- turtle.place()
- turtle.select(1)
- elseif ms == "r" then
- repeat
- turtle.forward()
- local senderId, msg, protocol = rednet.receive("tmzst",1)
- until msg == "r"
- end
- end
- end
- end
- local function send()
- while true do
- sleep(1)
- rednet.send(id,turtle.getFuelLevel(),"tmzstf")
- turtle.refuel()
- end
- end
- parallel.waitForAll(send,receive)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement