Summary

Functions

Registers a BB-code tag that can be used in chat messages.
Registers a chat filter that decides who receives messages of a type.
Registers a chat prefix that is checked against messages players type.
Builds a chat message from its arguments and sends it to the listeners that pass its filter.
Registers a chat message type.
Returns whether a player is within hearing range of a position.
Creates the chat box panel, replacing the existing one.
Creates the chat box panel and its text entry.
Creates the chat text entry inside the chat box, replacing the existing one.
Returns the callback of a BB-code tag.
Returns the text the local player is typing.
Returns the callback of a chat filter.
Returns the number of lines in the chat history, counting wrapped lines.
Returns the data registered for a chat prefix.
Returns the callback of a chat message type.
Hide()client
Closes the chat box.
IsOpen()client
Returns whether the chat box is open.
Returns whether the typed text is a command (starts with / or /? and is not OOC).
Returns whether the typed text starts with an OOC prefix (//, .// or [[).
Replaces the BB-code tags in a line of text with the objects their callbacks return.
Turns a message into the lines drawn by the chat box.
Returns whether a listener receives a message, according to the message's filter.
Removes the chat box panels and creates them again, closed.
Moves the chat box back to its default position in the bottom left corner.
Makes a player say something in character, as if they had typed it.
Sets chatbox.clientMode, which marks that the message being built was requested by a client.
Moves the chat box to a position on the screen.
Resizes the chat box.
Opens the chat box and focuses its text entry.
Rebuilds the drawn lines from the chat history.
Splits a message's text into pieces that fit the width of the chat box.

Functions

chatbox.AddBBCode(id, callback, requireRich)

client gamemodes/catwork/gamemode/core/libraries/cl_chatbox.lua:374

Registers a BB-code tag that can be used in chat messages.

The callback receives the value after = in the opening tag and the text up to the next tag, and returns the object inserted into the parsed line in place of the tag (usually a Color). It may return a replacement for the text as a second value.

chatbox.AddBBCode('red', function(value, text)
  return Color(255, 0, 0)
end)

Parameters

  • id String Name of the tag, such as 'color' for [color=...]
  • callback Function Called with the tag value and the following text
  • requireRich Boolean optional, defaults to true Whether the tag is only parsed in rich messages

chatbox.AddFilter(id, callback)

shared gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:81

On the server

Registers a chat filter that decides who receives messages of a type.

Messages pick their filter through msgData.filter ('ic', 'ooc', 'looc', 'admin', 'command' and so on). Registering an existing ID replaces it. Does nothing if the ID is empty.

chatbox.AddFilter('radio', function(listener, msgData)
  return listener:HasItemByID('handheld_radio')
end)

Parameters

  • id String Name of the filter
  • callback Function Called as callback(listener, msgData); return true to send the message to listener

See also

On the client

Registers a chat filter.

A filter is called with the message data before it is parsed and sets the message's display options (drawAvatar, drawTime, icon, rich, translate, type...). Does nothing when id is empty.

chatbox.AddFilter('radio', function(messageData)
  messageData.isPlayerMessage = true
  messageData.type = 'radio'
end)

Parameters

  • id String Unique ID of the filter, set as filter on messages
  • callback Function Called with the message data Map to change

See also

Defined in

chatbox.AddPrefix(prefix, callback)

server gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:37

Registers a chat prefix that is checked against messages players type.

The callback receives the message table and inspects msgData.text. When it returns a truthy value, the prefix is stripped from the text afterwards (for /? only the first character is stripped). The callback usually sets msgData.filter and msgData.radius. Does nothing if the prefix is empty.

chatbox.AddPrefix('!', function(msgData)
  if msgData.text:StartsWith('!') then
    msgData.filter = 'looc'
    msgData.radius = config.GetVal('talk_radius')

    return true
  end
end)

Parameters

  • prefix String The text messages must start with, such as '//'
  • callback Function Called as callback(msgData); return true once the message has been handled

See also

chatbox.AddText(listeners, ...)

shared gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:316

On the server

Builds a chat message from its arguments and sends it to the listeners that pass its filter.

Strings are appended to the text, Colors wrap the following text in [color=r,g,b,a] tags, players append their name and become the message's position and players entry, and tables are merged into the message to set fields such as filter, icon, radius, sender or textColor. The message defaults to the 'default' filter and the information icon.

Fires ChatAddText(listeners, message), then ChatboxAdjustMessageInfo(message, listeners) (returning false there cancels the message), sends the message over the ChatboxAddText Cable message to the listeners that pass its filter (an unknown filter counts as 'default') and finally fires ChatboxMessageSent(message).

chatbox.AddText(nil, Color(255, 100, 100), 'The server restarts in five minutes.', {
  filter = 'events',
  icon = 'icon16/error.png'
})

Parameters

  • listeners Player optional, defaults to nil A player or a list of players to send to; nil sends to everyone
  • ... Any Strings, colors, players and option tables making up the message

Returns

  • Map The message table with a listeners key added (the list of players it was sent to), or nil if a hook cancelled it or the only listener is no longer valid

See also

On the client

Asks the server to add a message to the local player's chat box.

The arguments are sent to the server, which builds the message with its own chatbox.AddText and sends it back to this player only.

chatbox.AddText(Color(255, 100, 100), 'You cannot do that.')

Parameters

  • ... Any Strings, Colors, players and message option tables

Defined in

Registers a chat message type.

A type is called with the message data after its filter and sets its colors and prefix (textColor, prefix, prefixColor, nameColorOverride...). Does nothing when id is empty.

Parameters

  • id String Unique ID of the type, set as type on messages
  • callback Function Called with the message data Map to change

See also

chatbox.CanHear(listener, position, radius)

server gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:106

Returns whether a player is within hearing range of a position.

The player hears it when the position is within radius of them, or within half the radius of the point they are looking at. Players that have not initialized never hear anything.

Parameters

  • listener Player The player who would hear the message
  • position Vector Where the message comes from; without one only a radius of 0 is heard
  • radius Number Hearing radius; 0 means everyone hears it, a negative value or a non-number means nobody does

Returns

  • Boolean Whether the listener can hear the message

Creates the chat box panel, replacing the existing one.

Creates the chat box panel and its text entry.

Creates the chat text entry inside the chat box, replacing the existing one.

Returns the callback of a BB-code tag.

Parameters

  • id String Name of the tag

Returns

  • Function The tag's callback, or nil if it is not registered

Returns the text the local player is typing.

Returns

  • String The text in the entry, or '' if the chat box is closed

On the server

Returns the callback of a chat filter.

Parameters

Returns

  • Function The filter callback, or nil if no filter has that name

On the client

Returns the callback of a chat filter.

Parameters

  • id String Unique ID of the filter

Returns

  • Function The filter, the default filter if id is unknown, or nil if id is empty

Defined in

Returns the number of lines in the chat history, counting wrapped lines.

Returns

  • Number Total line count of the stored messages

Returns the data registered for a chat prefix.

Parameters

Returns

  • Map The prefix data with Callback and length keys, or nil if it is not registered

Returns the callback of a chat message type.

Parameters

  • id String Unique ID of the type

Returns

  • Function The type, or nil if it is unknown or id is empty

Closes the chat box.

Runs the ChatBoxClosed hook with the typed text and then FinishChat. When Escape closed it, keeps the pause menu from opening.

See also

Returns whether the chat box is open.

Returns

  • Boolean Whether the chat box is open, or nil if it has not been created

Returns whether the typed text is a command (starts with / or /? and is not OOC).

Returns

  • Boolean Whether the player is typing a command

Returns whether the typed text starts with an OOC prefix (//, .// or [[).

Returns

  • Boolean Whether the player is typing an OOC message

chatbox.ParseBBCodes(line, rich)

client gamemodes/catwork/gamemode/core/libraries/cl_chatbox.lua:400

Replaces the BB-code tags in a line of text with the objects their callbacks return.

Changes line in place, splitting each string around its tags; tags that are not registered stay in the text. The result of the last tag is stored in chatbox.LastBBCode and inserted at the start of the next parsed line, so a color carries over wrapped lines.

Parameters

  • line List Strings and other objects making up a line
  • rich Boolean Whether tags that require rich messages are parsed

chatbox.ParseText(messageData)

client gamemodes/catwork/gamemode/core/libraries/cl_chatbox.lua:626

Turns a message into the lines drawn by the chat box.

Applies the message's filter ('ooc' when unset) and type, then builds the time, icon, avatar, prefix and sender name parts and wraps the text. Runs the ChatboxPreProcess and PreChatboxParse hooks with the message data and PostChatboxParse with the result. A filter or type that is not registered falls back to 'default'.

Parameters

  • messageData Map The message data received from the server

Returns

  • List<List> The lines; each starts with its vertical offset, followed by the sender, Colors, strings and marker strings such as '[SenderAvatar]'. The positions of the marker strings are the keys of the line's markers field

chatbox.PlayerCanHear(listener, messageData)

server gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:282

Returns whether a listener receives a message, according to the message's filter.

An invalid listener (such as the server console) receives everything except in-character messages.

Parameters

  • listener Player The player to check
  • messageData Map The message table; messageData.filter names the filter and defaults to 'default'

Returns

  • Boolean Whether the listener receives the message

See also

Removes the chat box panels and creates them again, closed.

Bound to the cw_resetchat console command.

Moves the chat box back to its default position in the bottom left corner.

See also

chatbox.SayAsPlayer(player, radius, text)

server gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:422

Makes a player say something in character, as if they had typed it.

The text is quoted and sent through chatbox.AddText with the 'ic' filter, so only players within the radius receive it.

Parameters

  • player Player The player who speaks
  • radius Number optional, defaults to nil Hearing radius; nil uses the talk_radius config
  • text String What the player says

See also

chatbox.SetClientMode(isclient)

server gamemodes/catwork/gamemode/core/libraries/sv_chatbox.lua:437

Sets chatbox.clientMode, which marks that the message being built was requested by a client.

The ChatboxAddText Cable receiver turns it on around its call to chatbox.AddText.

Parameters

  • isclient Boolean Whether client mode is on

chatbox.SetCustomPos(x, y, duration)

client gamemodes/catwork/gamemode/core/libraries/cl_chatbox.lua:109

Moves the chat box to a position on the screen.

The panel slides to the new position when it exists; otherwise the position is used when it is created.

Parameters

  • x Number Horizontal position
  • y Number Vertical position
  • duration Number optional, defaults to 0.25 Length of the move animation in seconds; defaults to chatbox.moveDuration

See also

chatbox.SetCustomSize(w, h, duration)

client gamemodes/catwork/gamemode/core/libraries/cl_chatbox.lua:125

Resizes the chat box.

The panel animates to the new size when it exists; otherwise the size is used when it is created.

Parameters

  • w Number New width
  • h Number New height
  • duration Number optional, defaults to 0.25 Length of the resize animation in seconds; defaults to chatbox.moveDuration

Opens the chat box and focuses its text entry.

Creates the panels first if needed.

Parameters

  • panel Panel optional, defaults to nil Panel to parent the chat box to; when nil the chat box becomes a popup

See also

Rebuilds the drawn lines from the chat history.

Parses up to 19 of the newest messages, skipping as many as the panel is scrolled, lays them out from the bottom up and prepares them for drawing. Called whenever a message arrives or the history is scrolled.

chatbox.WrapText(msgData, maxWidth, initWidth)

client gamemodes/catwork/gamemode/core/libraries/cl_chatbox.lua:512

Splits a message's text into pieces that fit the width of the chat box.

Translates the text first when the message has translate set and parses its BB-codes. Words longer than a line are broken with a dash.

Parameters

  • msgData Map The message data; reads text, translate, rich and data.sizeMultiplier
  • maxWidth Number Width of a line in pixels
  • initWidth Number optional, defaults to 0 Width already taken on the first line by the time, icon and name

Returns

  • List Strings and BB-code objects, with 'std::endl' marking each line break

Defined in