agot137

slave_switch.lua

Apr 25th, 2026 (edited)
2,618
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. local MODEM_SIDE = "bottom"
  2. local PROTOCOL = "rtm_top_switch"
  3. local native = term.current()
  4.  
  5. local function draw(on)
  6. term.redirect(native)
  7. term.setBackgroundColor(colors.black)
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. term.setTextColor(colors.yellow)
  11. print("SLAVE SWITCH")
  12. term.setTextColor(colors.white)
  13. print("ID: " .. os.getComputerID())
  14. print("Modem: " .. MODEM_SIDE)
  15. print("Redstone: top")
  16. print("")
  17. term.setTextColor(on and colors.lime or colors.gray)
  18. print("TOP JEL: " .. (on and "AKTIV" or "NINCS"))
  19. term.setTextColor(colors.lightGray)
  20. print("")
  21. print("Varakozas master parancsra...")
  22. end
  23.  
  24. local function setTop(enabled)
  25. redstone.setOutput("top", enabled)
  26. draw(enabled)
  27. end
  28.  
  29. rednet.open(MODEM_SIDE)
  30. setTop(false)
  31.  
  32. while true do
  33. local senderId, msg, protocol = rednet.receive(PROTOCOL)
  34. if type(msg) == "table" then
  35. if msg.cmd == "set_top" then
  36. local enabled = msg.enabled and true or false
  37. setTop(enabled)
  38. rednet.send(senderId, {
  39. ok = true,
  40. id = os.getComputerID(),
  41. enabled = enabled,
  42. }, PROTOCOL)
  43. elseif msg.cmd == "ping" then
  44. rednet.send(senderId, {
  45. ok = true,
  46. id = os.getComputerID(),
  47. enabled = redstone.getOutput("top"),
  48. }, PROTOCOL)
  49. elseif msg.cmd == "get_state" then
  50. rednet.send(senderId, {
  51. ok = true,
  52. id = os.getComputerID(),
  53. enabled = redstone.getOutput("top"),
  54. }, PROTOCOL)
  55. end
  56. end
  57. end
Advertisement
Comments
  • User was banned
    • User was banned
  • User was banned
    • User was banned
Add Comment
Please, Sign In to add comment