DorianH935

Untitled

Jul 13th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. local cb = peripheral.find("chatBox")
  2. local srn = peripheral.wrap("top")
  3.  
  4. local logFile = fs.open("log.txt", "a")
  5.  
  6. local lines = {}
  7.  
  8. while true do
  9. local event, username, message, uuid, isHidden = os.pullEvent("chat")
  10.  
  11. -- Log the chat to a file
  12. logFile.writeLine(username .. ": " .. message)
  13. logFile.flush()
  14.  
  15. -- Update the lines table with the new message
  16. table.insert(lines, username .. ": " .. message)
  17. if #lines > 15 then
  18. table.remove(lines, 1)
  19. end
  20.  
  21. -- Clear the screen
  22. srn.clear()
  23.  
  24. -- Display the chat on the monitor
  25. srn.setCursorPos(1, 1)
  26. for i = 1, #lines do
  27. srn.write(lines[i])
  28. srn.setCursorPos(1, i + 1)
  29. end
  30. end
  31.  
  32. logFile.close()
  33.  
Advertisement
Add Comment
Please, Sign In to add comment