Gekkeiju

TextAreaChatBox for Transformice

Dec 16th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. --[[
  2. This snippet "TextAreaChatBox" substitutes the TFM chat box as the area to show messages of the running script in Tribe house. This snippet is used because tfm.exec.chatMessage doesn't work in Tribe Houses.
  3.  
  4. - how to use it
  5. insert this snippet into your script and call
  6.     TextAreaChatBox.chatMessage(message, playerName)
  7. instead of
  8.     tfm.exec.chatMessage(message, playerName)
  9.  
  10. The table TextAreaChatBox must be loaded before the first call of TextAreaChatBox.chatMessage() in your script.
  11.  
  12. - example
  13. TextAreaChatBox = {...}
  14. TextAreaChatBox.chatMessage("Chat Box for Tribe House", nil)
  15.  
  16. ]]
  17.  
  18. TextAreaChatBox = {
  19.     ID = 123,   -- ID of the textArea used as a chat box
  20.     X = 10,
  21.     Y = 30,
  22.     WIDTh = 500,
  23.     HEIGHT = 150,
  24.     MAX_MESSAGES = 10, -- The maximum number of messages stored in the chat box
  25.     BACKGROUND_COLOR = 0x3E2C1D,    -- background color of the chat box
  26.     BACKGROUND_ALPHA = 0.3, -- opacity of the chat box
  27.     DEFAULT_TEXT_COLOR = "#FFFFFF", -- the default text color in the chat box. in the normal chat area of TFM, it's "#6C77C1".
  28.  
  29.     chatMessage =
  30.         function(message, name)
  31.             if not name then
  32.                 for name, player in pairs(tfm.get.room.playerList) do
  33.                     TextAreaChatBox.chatMessage(message, name);
  34.                 end
  35.             else
  36.                 local messages = TextAreaChatBox.messages[name];
  37.                 if not messages then
  38.                     messages = {};
  39.                     TextAreaChatBox.messages[name] = messages;
  40.                 end
  41.                 if #messages == TextAreaChatBox.MAX_MESSAGES then
  42.                     table.remove(messages, 1);
  43.                 end
  44.                 table.insert(messages, ([[<font color="%s">%s</font>]]):format(TextAreaChatBox.DEFAULT_TEXT_COLOR, message));
  45.                 ui.addTextArea(TextAreaChatBox.ID, table.concat(messages, "<br>"), name,
  46.                     TextAreaChatBox.X,
  47.                     TextAreaChatBox.Y,
  48.                     TextAreaChatBox.WIDTh,
  49.                     TextAreaChatBox.HEIGHT,
  50.                     TextAreaChatBox.BACKGROUND_COLOR,
  51.                     TextAreaChatBox.BACKGROUND_COLOR,
  52.                     TextAreaChatBox.BACKGROUND_ALPHA,
  53.                     true);
  54.             end
  55.         end,
  56.  
  57.     messages = {}
  58. }
Advertisement
Add Comment
Please, Sign In to add comment