Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MODEM_SIDE = "bottom"
- local PROTOCOL = "rtm_top_switch"
- local native = term.current()
- local function draw(on)
- term.redirect(native)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.yellow)
- print("SLAVE SWITCH")
- term.setTextColor(colors.white)
- print("ID: " .. os.getComputerID())
- print("Modem: " .. MODEM_SIDE)
- print("Redstone: top")
- print("")
- term.setTextColor(on and colors.lime or colors.gray)
- print("TOP JEL: " .. (on and "AKTIV" or "NINCS"))
- term.setTextColor(colors.lightGray)
- print("")
- print("Varakozas master parancsra...")
- end
- local function setTop(enabled)
- redstone.setOutput("top", enabled)
- draw(enabled)
- end
- rednet.open(MODEM_SIDE)
- setTop(false)
- while true do
- local senderId, msg, protocol = rednet.receive(PROTOCOL)
- if type(msg) == "table" then
- if msg.cmd == "set_top" then
- local enabled = msg.enabled and true or false
- setTop(enabled)
- rednet.send(senderId, {
- ok = true,
- id = os.getComputerID(),
- enabled = enabled,
- }, PROTOCOL)
- elseif msg.cmd == "ping" then
- rednet.send(senderId, {
- ok = true,
- id = os.getComputerID(),
- enabled = redstone.getOutput("top"),
- }, PROTOCOL)
- elseif msg.cmd == "get_state" then
- rednet.send(senderId, {
- ok = true,
- id = os.getComputerID(),
- enabled = redstone.getOutput("top"),
- }, PROTOCOL)
- end
- end
- end
Advertisement