Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MODEM_RS_CHANNEL = 127
- local ID = os.getComputerID()
- local modems = {}
- local side,channel,message
- local data = {}
- local waitForRS = false
- local event
- local eventSide
- local function startup()
- term.clear()
- term.setCursorPos(1,1)
- print("RS BOT "..ID)
- for i = 1,6 do
- if peripheral.getType(rs.getSides()[i]) == "modem" then
- modems[#modems+1] = peripheral.wrap(rs.getSides()[i])
- end
- end
- for i = 1,#modems do
- modems[i].open(MODEM_RS_CHANNEL)
- end
- local function send(command)
- for i = 1,#modems do
- peripheral.call(side,"transmit",MODEM_RS_CHANNEL,ID,command)
- end
- end
- startup()
- while true do
- event,side,channel,_,message = os.pullEvent("modem_message")
- _ = nil
- if event == "redstone" then
- if waitingForRS then
- side = eventSide
- send("gotEvent")
- end
- elseif event == "modem_message" then
- data = textutils.unserialize(message)
- if channel == MODEM_RS_CHANNEL
- and data[4] == ID then
- if data[1] == "setOutput" then
- rs.setOutput(data[3],data[2])
- elseif data[1] == "setAnalogOutput" then
- rs.setAnalogOutput(data[3],data[2])
- elseif data[1] == "setBundledOutput" then
- rs.setBundledOutput(data[3],data[2])
- elseif data[1] == "getInput" then
- send(rs.getInput(data[3]))
- elseif data[1] == "getAnalogInput" then
- send(rs.getAnalogInput(data[3]))
- elseif data[1] == "getBundledInput" then
- send(rs.getBundledInput(data[3]))
- elseif data[1] == "getOutput" then
- send(rs.getOutput(data[3]))
- elseif data[1] == "getAnalogOutput" then
- send(rs.getAnalogOutput(data[3]))
- elseif data[1] == "getBundledOutput" then
- send(rs.getBundledOutput(data[3]))
- elseif data[1] == "testBundledInput" then
- send(rs.testBundledOutput(data[3],data[2]))
- end
- end
- if channel == MODEM_RS_CHANNEL then
- if data[1] == "event true" then
- eventSide = side
- waitForRS = true
- elseif data[1] == "event false" then
- waitForRS = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment