Display Typing shows players a bubble for everyone nearby who is typing in the chatbox. The bubble names the typing player, says what kind of speech they are typing (talking, whispering and so on) and, if the server and the viewer allow it, shows the text as it is being typed. It sits above the head of a player who is in view and is held at the edge of the screen, with a pointer towards the player, for one who is off screen or behind the viewer.
The client of a typing player reports the text to the server a few times a second, and the
server passes it on only to the players who are near enough to see the bubble; players who
are dead, hidden or in observer mode are not shown as typing at all. When the
'display_exact_message' config is disabled, or the text is a command that no plugin has
claimed as speech, the text itself never leaves the client: only its outline is sent (see
DisplayTyping:outline), which is enough for hooks to tell the kind of speech.
The kind of speech is decided on the client by the DisplayTypingGetKind hook, which
returns the ID of a kind registered with DisplayTyping:register_kind. The client of the
typing player reports that ID, and the server takes the range the bubble is sent within
from the kind, so a kind has to be registered on both realms for its range to count. When
that hook decides nothing, the DisplayTypingTextType and
DisplayTypingAdjustFadeoffMultiplier hooks give a label and a range, but that range only
scales the distance the bubble fades at on the viewer's client. Each player can turn the
bubbles or the live text off in the client settings, if the Settings plugin is loaded.
Summary
Hooks
scan_interval seconds.Methods
report_limit reports a second.report_interval.report_interval seconds, otherwise when that time is up.relay_interval seconds and otherwise on the next LazyTick after that.Hooks
Implements hook ChatTextChanged
Reports the text the local player is typing in the chatbox. The chatbox runs this with an empty string when it closes, which is also what happens after a message is sent, and that ends the typing.
Parameters
- new_text String current contents of the chat text entry
DisplayTyping:ClientSettingChanged(id, _value, _old_value)
client plugins/displaytyping/plugin/cl_hooks.lua:63Implements hook ClientSettingChanged
Has the bubbles show or hide the live text when the local player switches the setting.
Parameters
- id String setting id
- _value Any new value of the setting
- _old_value Any previous value of the setting
Draws the typing bubbles, unless the HUD is hidden.
Implements hook LazyTick
Looks after the typing players eight times a second: ends the typing of those who have
reported nothing for too long, sends changes that had to wait for the relay interval and
checks again who is in range of each of them every scan_interval seconds.
DisplayTyping:OnConfigReceived(key, _old_value, _new_value)
client plugins/displaytyping/plugin/cl_hooks.lua:74Implements hook OnConfigReceived
Has the bubbles show or hide the live text when the server switches the 'display_exact_message' config.
Parameters
- key String config key
- _old_value Any value the client had before
- _new_value Any value that has been received
DisplayTyping:OnScreenSizeChanged(_old_width, _old_height, _new_width, _new_height)
client plugins/displaytyping/plugin/cl_hooks.lua:55Has the sizes of the bubbles worked out again for the new size of the screen.
Parameters
- _old_width Number previous screen width
- _old_height Number previous screen height
- _new_width Number new screen width
- _new_height Number new screen height
Implements hook OnThemeLoaded
Has the look of the bubbles read from the theme again once it has been loaded.
Parameters
- _current_theme ThemeBase
Implements hook PlayerDisconnected
Ends the typing of a player who leaves the server.
Parameters
- actor Player
Implements hook RegisterClientSettings
On the server
Registers the networked client setting of the plugin on the server, so that it knows which players have turned typing bubbles off. Only called if the Settings plugin is loaded.
On the client
Registers the client settings of the plugin: whether the player sees typing bubbles at all, which the server is told so that it does not send them anything, and whether the bubbles show the text as it is typed. Only called if the Settings plugin is loaded.
Defined in
Methods
Counts a typing report of a player against the limit of report_limit reports a second.
Parameters
- actor Player the player who has sent the report
- now Number current CurTime()
Returns
- Boolean false if the player has sent too many reports this second
Works out where a bubble wants to be on the screen. If the head of the player is on screen the bubble goes above it, kept within the margins. Otherwise it goes to the edge of the screen in the direction of the player as seen from the middle of the screen; a player behind the viewer is pulled towards the bottom edge the further behind they are. A bubble that is not tracking its player this frame keeps the place it had.
Parameters
- bubble Map
Moves bubbles apart so that they do not cover each other. Older bubbles keep the place they want; a newer one that would overlap is moved up or down until it is clear of the ones before it. A bubble above a head moves up, away from the player, unless it is close to the top of the screen; one at the edge moves towards the middle of the screen.
Parameters
- count Number how many bubbles are listed for drawing this frame
Checks whether other players may be shown that a player is typing. They may not while the player is dead, not initialized, vanished, in observer mode or not drawn (unless they have fallen over and a ragdoll stands in for them), or when the PlayerCanDisplayTyping hook says so.
Parameters
- actor Player the typing player
Returns
- Boolean
Checks whether a player is sent the typing of others: bots and players who have not been initialized or have turned typing bubbles off in their client settings are not.
Parameters
- viewer Player
Returns
- Boolean
Draws a bubble: the box with its pointer, the animated dots, the name, the label of the kind of speech and the live text with a blinking caret. The PaintTypingBubble theme hook can take the drawing over.
Parameters
- bubble Map
- now Number RealTime() of the frame
Updates and draws all typing bubbles for the frame: fades each one towards the opacity it should have, forgets the ones that have finished and faded out, then lays out, places, moves and draws the rest. Nothing is shown while the player has typing bubbles turned off in the client settings. If the bubbles have not been drawn for half a second, because the HUD was hidden, they start over from invisible rather than from where they were left.
Returns a registered kind of speech.
Parameters
- id String ID of the kind
Returns
- Map kind definition, or nil if it is not registered
Sends the report that is waiting to be sent, if there is one, and starts the next
report_interval.
Tells what kind of speech a text is, by asking the DisplayTypingGetKind hook and, if it decides nothing, the DisplayTypingTextType and DisplayTypingAdjustFadeoffMultiplier hooks.
Parameters
- target Player the player who is typing
- text String the text being typed, or its outline
Returns
- Map the kind: id (String), label (String translated label), color (Color, or nil for the accent color of the bubble), range (Number multiplier of the 'display_typing_range' config) and live (Boolean whether the text may be shown); nil if no bubble should be shown for this text
Reads a client setting of the plugin. Settings are on while the Settings plugin is not loaded.
Parameters
- id String setting id
Returns
- Boolean false if the player has turned the setting off
Returns the ragdoll that stands in for a player who has fallen over, if the Ragdoll plugin is loaded.
Parameters
- target Player
Returns
- Entity the ragdoll, or nil if the player has none
Returns the distance within which the bubble of a typing player is visible, before the kind of speech scales it.
Returns
- Number distance in units, the 'display_typing_range' config
DisplayTyping:has_sight(bubble, target, position, now)
client plugins/displaytyping/plugin/lib/cl_bubbles.lua:263Checks whether the local player has a clear line of sight to a typing player. The trace
is repeated every sight_interval seconds for each bubble, and a line of sight that has
been lost still counts for sight_grace seconds, so that bubbles do not flicker when
something passes in between. Always true if the 'display_typing_through_walls' config is
enabled.
Parameters
- bubble Map the bubble of the typing player
- target Player the typing player
- position Vector position of the head of the typing player
- now Number RealTime() of the frame
Returns
- Boolean
Has the fonts, colors and sizes of the bubbles read from the theme again before the next frame. The plugin does so when a theme has been loaded, the screen size has changed and the live text setting or config has been switched.
On the server
Checks whether a player is typing in the chatbox, as far as their client has reported.
Parameters
- target Player
Returns
- Boolean
On the client
Checks whether a player is known to be typing. On the client that is known for the local player and for the players whose typing bubbles the server has sent, which are the ones nearby.
Parameters
- target Player
Returns
- Boolean
Defined in
Works out what a bubble shows and how large it has to be: the label and the color of the kind of speech, the wrapped lines of the live text if it is shown, and the size the bubble eases towards. The lines are only wrapped again when the text or the look has changed, and the name and the label are only measured again when they or their fonts have changed.
Parameters
- bubble Map
Checks whether the server lets players see the text that others are typing.
Returns
- Boolean false if the 'display_exact_message' config is disabled
Eases a bubble towards its place and size. A bubble that has just appeared starts there. A bubble above a head follows quickly, one at the edge of the screen glides.
Parameters
- bubble Map
- delta Number seconds since the last frame
Reduces a text to its outline: what it starts and ends with, without anything it says.
The outline keeps the command at the start of the text (the command prefix and the name
made of Latin letters, digits and underscores) or else the punctuation it starts with, and
the punctuation it ends with; everything in between is replaced with a single ellipsis
(DisplayTyping.placeholder). It is what other players receive in place of a text they
are not allowed to see, so that the hooks that tell the kind of speech by a prefix or an
ending still work. The outline of an outline is the same outline.
DisplayTyping:outline('/me waves his hand.') -- '/me ….'
DisplayTyping:outline('(over here') -- '(…'
DisplayTyping:outline('Watch out!!') -- '…!!'
DisplayTyping:outline('Hello there') -- '…'
Parameters
- text String text to reduce
Returns
- String the outline; an empty string for an empty text, the placeholder alone for a text that is not valid UTF-8
Registers a kind of speech that a typing bubble can show. A kind gives the bubble its label and color and scales the distance it is visible from.
DisplayTyping:register_kind('whispering', {
name = 'ui.hud.display_typing.whispering',
color = Color(150, 170, 200),
range = 0.25
})
function MyPlugin:DisplayTypingGetKind(target, text)
if text:start_with('/w ') then
return 'whispering'
end
end
Parameters
- id String unique ID of the kind
- data Map kind definition, all fields optional: name (String phrase or text of the label, the 'typing' label by default), color (Color of the label and the animated dots, the accent color of the bubble by default), range (Number multiplier of the 'display_typing_range' config for this kind, 1 by default), live (Boolean whether the text may be shown as it is typed, true by default)
Returns
- Map the registered kind, or nil if the arguments are not valid
Brings the players near a typing player up to date. Works out who should see the typing now, tells the players who no longer should that it is over, and sends the state to the players who have come into range, or to everyone in range if it has changed.
Parameters
- actor Player the typing player
- state Map typing state of the player
- now Number current CurTime()
Takes the text the local player is typing and reports it to the server if what others
should see has changed: at once if nothing has been sent for report_interval seconds,
otherwise when that time is up. An empty text, or one that no bubble is shown for, ends
the typing right away. While the player keeps typing a text that looks the same to others,
the report is repeated every keepalive_interval seconds so that the server knows they
are still at it. A report carries the ID of the kind of speech, from which the server
takes the range of the bubble.
Parameters
- text String current contents of the chat text entry
DisplayTyping:set_typing(actor, text, exact, kind_id)
server plugins/displaytyping/plugin/sv_plugin.lua:92Records what a player is typing and passes it on to the players nearby, at once if
nothing has been sent about this player for relay_interval seconds and otherwise on the
next LazyTick after that. The typing ends by itself if no report follows for
idle_timeout seconds.
Parameters
- actor Player the typing player
- text String the text being typed or its outline, not empty
- exact Boolean optional, defaults to
falsetrue if the text is what the player is typing and others may see it; otherwise it is reduced to its outline - kind_id String optional, defaults to
nilID of the kind of speech, as registered withDisplayTyping:register_kindon both realms; its range scales the 'display_typing_range' config for this text, limited toDisplayTyping.max_range. A kind the server does not know gets the range 1
Marks the typing bubble of a player as finished, which makes it fade out and go away.
Parameters
- index Number entity index of the player
Ends the typing of a player and tells the players who were shown it.
Parameters
- actor Player
DisplayTyping:update_bubble(index, text, exact)
client plugins/displaytyping/plugin/lib/cl_bubbles.lua:219Creates or updates the typing bubble of a player with what the server has sent about them. A bubble that was fading out comes back.
Parameters
- index Number entity index of the typing player
- text String the text being typed, or its outline
- exact Boolean true if the text is what the player is typing rather than its outline
Reads the fonts, colors and sizes of the bubbles from the active theme, falling back to
the general fonts and colors of the theme, and whether live text is shown. Done before the
first frame and again after DisplayTyping:invalidate_metrics, not every frame.
Brings a bubble up to date with its player for the frame: finds the player, works out the kind of speech again if the text has changed, refreshes the name and the position of the head, and decides how visible the bubble should be.
Parameters
- bubble Map
- now Number RealTime() of the frame
Returns
- Number opacity the bubble should have, from 0 (hidden) to 1; it falls off over the last part of the range