Chatbox replaces the default chat of the game with the chat of Flux.
Every message goes through the server. Chatbox.add_text builds a message out of strings,
colors, font sizes, icons, avatars, players and entities and sends it to the players who can
hear it, and Chatbox.player_say does the same for what a player has typed. On the client a
message is compiled into pieces that can be drawn (Chatbox.compile) and added to the
chatbox panel, which also lists the matching commands while one is being typed.
chat.AddText is redirected to the chatbox too, and what is typed with say in the server
console is shown as a line of the console.
Plugins shape the chat through hooks: PlayerSay and ChatboxAdjustPlayerSay change what a
player says, ChatboxGetPlayerIcon, ChatboxGetPlayerColor and ChatboxGetMessageColor
style it, ChatboxShouldSendMessage can cancel a message, AdjustMessageData and
PlayerCanHear decide who receives it, ChatboxMessageSent tells who has received it, and
ChatboxCompileMessage, ChatboxShouldAddMessage and ChatboxPrePaintMessage take over
how it is displayed. Font sizes, the message limit, the fade delay, the length of a message,
the interval between two messages of a player, avatars and timestamps are set through the
config keys of the chatbox category.
Summary
Hooks
say in the server console as a chat line of the console.say and say_team console commands, which the engine runs this hook for and would otherwise broadcast itself: the text goes through Chatbox.submit, so that the flood guard and the length limit apply to it as they do to the chatbox, and the engine is told to say nothing.Functions
Chatbox.submit is running.say console command: the text is dropped, and the player told so once a second at most, while the 'chat_interval' config has not passed since their last submission (see Chatbox.check_interval); otherwise it is cut to the 'max_message_length' config (see Chatbox.limit_text) and passed to Chatbox.player_say.Hooks
Chatbox:ChatboxGetMessageColor(_speaker, _text, _team_chat)
server plugins/chatbox/plugin/sv_hooks.lua:30Implements hook ChatboxGetMessageColor
Provides the default color of the text of chat messages.
Parameters
- _speaker Player the speaker
- _text String the message
- _team_chat Boolean whether the message was sent to the team chat
Returns
- Color white
Chatbox:ChatboxGetPlayerColor(speaker, _text, _team_chat)
server plugins/chatbox/plugin/sv_hooks.lua:21Implements hook ChatboxGetPlayerColor
Provides the default color of the player's name in their chat messages.
Parameters
- speaker Player the speaker
- _text String the message
- _team_chat Boolean whether the message was sent to the team chat
Returns
- Color the color of the player's team
Chatbox:ChatboxGetPlayerIcon(_speaker, _text, _team_chat)
server plugins/chatbox/plugin/sv_hooks.lua:12Implements hook ChatboxGetPlayerIcon
Provides the default icon that is displayed before the name of the player in their chat messages.
Parameters
- _speaker Player the speaker
- _text String the message
- _team_chat Boolean whether the message was sent to the team chat
Returns
- Map icon piece for Chatbox.add_text
Implements hook ChatboxMessageCompiled
Prints the texts and colors of a compiled chat message to the console.
Parameters
- compiled Map compiled message, as returned by Chatbox.compile
Implements hook ChatboxTextEntered
Sends the entered text to the server, unless it is empty, along with whether the chatbox was opened for team chat, and closes the chatbox.
Parameters
- text String the text that was entered
Implements hook CreateFonts
Creates the normal, bold, italic and bold italic fonts of the chatbox.
Closes the chatbox when the player clicks on the game world.
Parameters
- _mouse_code Number mouse button code
- _aim_vector Vector direction of the click
Hides the default chat HUD element.
Parameters
- element String name of the HUD element
Returns
- Boolean false for 'CHudChat', nil otherwise
Chatbox:OnPlayerChat(speaker, text, _team_chat, _is_dead)
client plugins/chatbox/plugin/cl_hooks.lua:152Shows what is typed with say in the server console as a chat line of the console. The
engine delivers such text to every client with an invalid speaker; what players say
through the engine is left to the gamemode.
Parameters
- speaker Player the speaker, an invalid entity for the server console
- text String the message
- _team_chat Boolean whether the message was sent to the team chat
- _is_dead Boolean whether the speaker is dead
Returns
- Boolean true to suppress the default handling of a console message, nil otherwise
Implements hook OnResolutionChanged
Recalculates the size and position options of the chatbox for the new resolution and removes the chatbox panel so that it gets recreated.
Parameters
- new_width Number new screen width
- new_height Number new screen height
Implements hook OnThemeLoaded
Sets the options, fonts and colors of the chatbox on the theme that was loaded.
Parameters
- current_theme ThemeBase
Opens the chatbox instead of the default chat when a chat bind is pressed, remembering whether team chat was requested.
Parameters
- _client Player
- bind String the bind that was pressed
- pressed Boolean whether the bind was pressed rather than released
Returns
- Boolean true to block the bind if the chatbox was opened, nil otherwise
Implements hook PlayerCanHear
Makes sure that the sender of a message always receives it.
Parameters
- listener Player the listener
- message_data Map message data, see Chatbox.add_text
Returns
- Boolean true if the player is the sender of the message, nil otherwise
Implements hook PlayerSay
Takes over what a player says through the say and say_team console commands, which
the engine runs this hook for and would otherwise broadcast itself: the text goes through
Chatbox.submit, so that the flood guard and the length limit apply to it as they do to
the chatbox, and the engine is told to say nothing. A command is left to the gamemode
handler, and the text that Chatbox.submit itself passes to Chatbox.player_say, which
runs this hook again, is left alone as well.
Parameters
- actor Player the speaker
- text String the text as it was typed
- team_chat Boolean whether the text is meant for the team chat
Returns
- String an empty string once the text has been taken over, nil otherwise
Functions
Stores a message filter under the specified id. Serverside only. The chatbox itself does not read the stored filters.
Parameters
- id String unique filter id
- data Map filter data
Adds a message to the chatbox of the local player and plays the chat sound, creating the chatbox panel first if necessary. This is what happens to every message that arrives from the server; call it directly to show a message that only exists on this client. Does nothing if there is no panel and the theme has not been initialized yet. Clientside only.
Chatbox.add_message({ data = { Color(255, 200, 0), 'Only you can see this.' } })
Parameters
- message_data Map message data: data (List of strings, font sizes, colors, image, icon and avatar tables, players and entities), optional size, time and should_translate
See also
Builds a chat message from the arguments and sends it to the listeners that can
hear it. Serverside only.
Strings are displayed as text, numbers set the font size of the following text,
colors set its color, players and entities are displayed by their names. Tables with
is_data = true are displayed as icons, images or Steam avatars (see Chatbox.avatar).
Any other table is merged into the message options: sender, position, radius (0 is
global), size, should_translate, time (when the message was sent, the current
os.time() by default; shown when the 'chat_timestamps' config is enabled).
The ChatboxShouldSendMessage hook can cancel the message before anyone receives it, and the ChatboxMessageSent hook is run with the players who have received it. Neither is run for the text that a client adds with chat.AddText.
-- Message for everyone.
Chatbox.add_text(nil, Color(255, 200, 0), 'The server restarts in 5 minutes!')
-- Message from a player that is heard within 300 units of them.
Chatbox.add_text(nil,
{ icon = 'fa-shield-alt', size = 14, margin = 8, is_data = true },
team.GetColor(actor:Team()), actor, Color(255, 255, 255), ': ', text,
{ sender = actor, position = actor:GetPos(), radius = 300 }
)
-- Message for certain players only.
Chatbox.add_text(Bolt:get_staff(), Color(234, 255, 208), '@staff ', actor, ': ', text)
Parameters
- listeners List<Player>/Player the receivers, nil to send to all players; a player who is not valid receives nothing
- ... Vararg pieces of the message and option tables
See also
Returns a message piece that displays the Steam avatar of a player in a chat message.
Pass the piece to Chatbox.add_text (or to chat.AddText on the client) at the place of
the message where the avatar should be. The piece holds the SteamID64 rather than the
player, so the avatar stays in the chat history after the player has left.
-- The avatar of the speaker before their name.
Chatbox.add_text(nil, Chatbox.avatar(actor), team.GetColor(actor:Team()), actor,
Color(255, 255, 255), ': ', text, { sender = actor })
-- Only when the server has avatars enabled; an empty table adds nothing to a message.
Chatbox.add_text(nil, Config.get('chat_avatars') and Chatbox.avatar(actor) or {}, actor, ': ', text)
Parameters
- target Player/String the player, or a SteamID64
- size Number optional, defaults to
nilwidth and height of the avatar before screen scaling; the height of a line of text at that place of the message when omitted - margin Number optional, defaults to
8horizontal space around the avatar before screen scaling, half of it on each side
Returns
- Map avatar piece: avatar (String SteamID64), size, margin and is_data = true; the piece displays nothing if the target is neither a player nor a string
Checks whether the listener should receive the message. Serverside only. The PlayerCanHear hook can force a message through. Otherwise a radius of 0 reaches every initialized player, a negative radius reaches nobody, and a positive radius reaches the players whose eyes are within it from the position of the message.
Parameters
- listener Player
- message_data Map message data with radius (Number) and position (Vector or List<Vector>), see Chatbox.add_text
Returns
- Boolean
Checks whether the player may submit a chat message now, that is whether the 'chat_interval' config (in milliseconds) has passed since their last accepted submission. A submission that is accepted starts the next interval. Serverside only.
Parameters
- actor Player the player who submits a message
Returns
- Boolean false if the player has to wait, true otherwise
Converts a message that was received from the server into a list of pieces with calculated sizes and positions, ready to be drawn by a fl_chat_message panel. Strings are wrapped to the width of the chatbox. While the 'chat_timestamps' config is enabled the message starts with the time it was sent at. Clientside only.
Parameters
- msg_table Map message data: data (List of strings, font sizes, colors, image / icon / avatar tables, players and entities), optional size, time (os.time() of the message, the current time when omitted) and should_translate
Returns
- Map sequential pieces: font sizes (Number), colors (Color), texts ({ text, w, h, x, y }), images ({ image or icon, x, y, w, h }) and avatars ({ avatar, x, y, w, h }), plus the total_height field; nil if the chatbox font is not available
Creates the chatbox panel in its closed state, taking the size and position from the current theme. The panel is stored in Chatbox.panel.
Closes the chatbox, disables its mouse and keyboard input and runs the ChatTextChanged hook with an empty string.
Checks whether a text that a player has submitted is being turned into a message at the
moment, that is whether Chatbox.submit is running. The PlayerSay hook that
Chatbox.player_say runs then comes from the chatbox itself and not from the engine.
Serverside only.
Returns
- Boolean
Cuts a text that a player has submitted down to the 'max_message_length' config, counted in characters like the limit of the chatbox text entry. A text that is not valid UTF-8 is cut to that many bytes instead. Serverside only.
Parameters
- text String the submitted text
Returns
- String the text, no longer than the limit
Chatbox.message_to_string(message_data, concatenator)
server plugins/chatbox/plugin/sv_plugin.lua:230Joins the strings of a message into a single string. Players and entities are replaced with their names, numbers and other values are skipped.
Parameters
- message_data List pieces of a message, such as the data of a message
- concatenator String optional, defaults to
''separator to put between the pieces
Returns
- String
Makes the player say the text in the chat, by default to all players. Runs the PlayerSay hook first, which may change or suppress the text. The icon and colors come from the ChatboxGetPlayerIcon, ChatboxGetPlayerColor and ChatboxGetMessageColor hooks, and the ChatboxAdjustPlayerSay hook can alter the finished message. Serverside only.
Parameters
- actor Player the speaker
- text String the message
- team_chat Boolean optional, defaults to
nilwhether the message was sent to the team chat
Internal
This function is internal. It is not part of the public API and may change without notice.
Toggles the mode in which Chatbox.add_text displays every table instead of merging tables into the message options. Enabled while relaying chat.AddText of a client.
Parameters
- val Boolean
Opens the chatbox, creating its panel first if necessary. Does nothing if there is no panel and the theme has not been initialized yet.
Makes a player say a text they have submitted, from the chatbox or the say console
command: the text is dropped, and the player told so once a second at most, while the
'chat_interval' config has not passed since their last submission (see
Chatbox.check_interval); otherwise it is cut to the 'max_message_length' config (see
Chatbox.limit_text) and passed to Chatbox.player_say. Serverside only.
Parameters
- actor Player the player who has submitted the text
- text String the text as it was typed
- team_chat Boolean optional, defaults to
nilwhether the text is meant for the team chat
Returns
- Boolean true if the text has been passed to Chatbox.player_say without an error, false otherwise