Advertisement
Urara_Chiya

chat_listener.lua

Jan 28th, 2025 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. -- Wrap the Chat Box peripheral
  2. local chatBox = peripheral.find("chatBox")
  3. if not chatBox then
  4. error("Chat Box not found. Please connect one to the computer.")
  5. end
  6.  
  7. -- Initialize the back redstone output
  8. redstone.setOutput("back", false)
  9.  
  10. print("Listening for chat messages...")
  11.  
  12. while true do
  13. -- Capture the "chat" event
  14. local event, playerName, message = os.pullEvent("chat")
  15.  
  16. -- Check for the specific player and message
  17. if playerName == "aabbcc" and message == "ccbbaa" then
  18. print("Message detected, sending redstone pulse!")
  19.  
  20. -- Send a redstone pulse
  21. redstone.setOutput("back", true)
  22. sleep(1)
  23. redstone.setOutput("back", false)
  24.  
  25. -- Broadcast a chat message to all players
  26. chatBox.sendMessage("Redstone signal triggered by player: " .. playerName)
  27. end
  28. end
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement