Game text: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Add internal names of keyval keys)
m (updated template usage.)
Line 1: Line 1:
{{base point|game_text|sprite=1}} It displays text on players' screens. This text can be defined directly in the Hammer editor (unlike the similar {{ent|env_message}} entity which uses the <code>titles.txt</code> file).
{{lang|Game text}}
 
{{point ent|game_text|sprite=1}}  
In multiplayer games, the text will normally only display for the activator of the "Display" input. The "All Players" flag can be ticked in order to display on the screens of all players.
 
{{clr}}
 
{{note|If you are creating a mod with its own files and scripts, it's recommended to use the aforementioned {{ent|env_message}} entity, which uses the <code>titles.txt</code> script for text parameters instead of keyvalues, allowing the text to be changed without having to recompile any maps. It also supports newlines and quotation marks, unlike regular <code>game_text</code>.}}
 
{{tip|Despite comments stating otherwise, <code>game_text</code> supports localized strings (e.g. <code>#HL2_Chapter4_Title</code>) in most or all Source games.}}
 
{{Warning|VMFs can become corrupted when using quotation marks (") in any entity's keyvalues or I/O, so quotation marks cannot be used in the ''Text Message'' field (not even <code>\"</code> characters). You can use two apostrophes (<nowiki>''</nowiki>) or detailed quotes (i.e. <code>&ldquo;</code> and <code>&rdquo;</code>) instead.}}
 
{{Bug|Doesn't work in {{Game link|Left 4 Dead 2}}}}
 
{{Bug|Scales incorrectly for players that have game resolution higher than 1920x1080, text will be much larger and some text will be hidden. {{todo|Is this {{csgo}} only?}}}}
 


==Entity Description==
This entity displays text on players' screens. This text can be defined directly in the Hammer editor (unlike the similar {{ent|env_message}} entity, which uses the <code>titles.txt</code> file). In multiplayer games, the text will normally only display for the activator of the "Display" input. The "All Players" flag can be ticked in order to display on the screens of all players.
{{note|If you are creating a mod with its own files and scripts, it's recommended to use the aforementioned <tt>env_message</tt> entity, which uses the <code>titles.txt</code> script for text parameters instead of keyvalues, allowing the text to be changed without having to recompile any maps. It also supports newlines and quotation marks, unlike regular <code>game_text</code>.}}
{{tip|Despite comments stating otherwise, <code>game_text</code> supports localized strings (e.g., <tt>#HL2_Chapter4_Title</tt>) in most or all Source games.}}
{{Warning|VMFs can become corrupted when using quotation marks (<tt>"</tt>) in any entity's keyvalues or I/O, so quotation marks cannot be used in the ''Text Message'' field (not even <tt>\"</tt> characters). You can use two apostrophes (<tt><nowiki>''</nowiki></tt>) or detailed quotes (i.e., <tt>&ldquo;</tt> and <tt>&rdquo;</tt>) instead.}}
{{Bug|Doesn't work in {{l4d2|2}}.}}
{{Bug|Scales incorrectly for players that have game resolution higher than 1920x1080. Text will be much larger and some text will be hidden. {{todo|Is this {{csgo}} only?}}}}
{{code class|CGameText|maprules.cpp}}
{{code class|CGameText|maprules.cpp}}


== Keyvalues ==
== Keyvalues ==
{{KV|Message Text|intn=message|string|Message to display onscreen. \n signifies a new line in the text. {{tip|[[AddOutput]] <code>message</code> can be used to change text at runtime in older games which do not support <code>SetText</code>.}} {{bug|Hammer will automatically change <code>\n</code> to <code>/n</code>. This can be worked around by editing the VMF with a text editor, although it will need to be changed every time after each save.}}}}
{{KV|Message Text|intn=message|string|Message to display onscreen. <tt>\n</tt> signifies a new line in the text. {{bug|Hammer will automatically change <tt>\n</tt> to <tt>/n</tt>. This can be worked around by editing the VMF with a text editor, although it will need to be changed every time after each save.}}}}
{{KV|X (0 - 1.0 {{=}} left to right) (-1 centers)|intn=x|string|Horizontal position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the far left of the screen and 1 is the far right. -1 centers the text.}}
{{KV|X (0 - 1.0 {{=}} left to right) (-1 centers)|intn=x|string|Horizontal position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the far left of the screen and 1 is the far right. -1 centers the text.}}
{{KV|Y (0 - 1.0 {{=}} top to bottom) (-1 centers)|intn=y|string|Vertical position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the top of the screen and 1 is the bottom. -1 centers the text.}}
{{KV|Y (0 - 1.0 {{=}} top to bottom) (-1 centers)|intn=y|string|Vertical position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the top of the screen and 1 is the bottom. -1 centers the text.}}
{{KV|Text Effect|intn=effect|choices|Text scan effect}}
{{KV|Text Effect|intn=effect|choices|Text scan effect}}
:*0: Fade In/Out. The whole text is faded in, and then faded out.
:*0: Fade In/Out. The whole text is faded in, and then faded out.
:*1: Credits {{todo|Unknown - seems to act like Fade In/Out. Provide description.}}
:*1: Credits {{todo|Unknown—seems to act like Fade In/Out. Provide description.}}
:*2: Scan Out. The text is scanned in letter by letter, and the whole text is then faded out.
:*2: Scan Out. The text is scanned in letter by letter, and the whole text is then faded out.
{{KV|Color1|intn=color|color255|The primary color used by all the text effects. {{note|The color values seem to be added to the background, so either a bright white background or black text will cause the message to be invisible.}} {{note|This keyvalue will default to black for entities not created in Hammer.}} }}
{{KV|Color1|intn=color|color255|The primary color used by all the text effects. {{note|The color values seem to be added to the background, so either a bright white background or black text will cause the message to be invisible.}} {{note|This keyvalue will default to black for entities not created in Hammer.}} }}
{{KV|Color2|intn=color2|color255|The scanning color for the letter being scanned if the ''Text Effect'' keyvalue is set to ''Scan Out'' - usually a different shade of Color1.}}
{{KV|Color2|intn=color2|color255|The scanning color for the letter being scanned if the ''Text Effect'' keyvalue is set to ''Scan Out''—usually a different shade of Color1.}}
{{KV|Fade in Time (or character scan time)|intn=fadein|string|The time it should take for the text to fully fade in.}}
{{KV|Fade in Time (or character scan time)|intn=fadein|string|The time it should take for the text to fully fade in.}}
{{KV|Fade Out Time|intn=fadeout|string|The time it should take for the text to fade out, after the hold time has expired.}}
{{KV|Fade Out Time|intn=fadeout|string|The time it should take for the text to fade out, after the hold time has expired.}}
{{KV|Hold Time|intn=holdtime|string|The time the text should stay onscreen, after fading in, before it begins to fade out.{{note|This value defaults to zero for entities not created in Hammer.}}}}
{{KV|Hold Time|intn=holdtime|string|The time the text should stay onscreen, after fading in, before it begins to fade out.{{note|This value defaults to zero for entities not created in Hammer.}}}}
{{KV|Scan time (scan effect only)|intn=fxtime|string|If the 'Text Effect' is set to Scan Out, this is the time it should take to scan out all the letters in the text.}}
{{KV|Scan time (scan effect only)|intn=fxtime|string|If the 'Text Effect' is set to Scan Out, this is the time it should take to scan out all the letters in the text.}}
{{KV|Text Channel|intn=channel|choices|You can have up to six individual game_text messages onscreen at once, stored in channels. Select which channel this text should be placed in, which will overwrite any active message already in that channel.}}
{{KV|Text Channel|intn=channel|choices|You can have up to six individual <tt>game_text</tt> messages onscreen at once, stored in channels. Select which channel this text should be placed in, which will overwrite any active message already in that channel.}}
:*0: Channel 0 (unused) {{Not in FGD}}
:*0: Channel 0 (unused) {{Not in FGD}}
:*1: Channel 1 (medium text size)
:*1: Channel 1 (medium text size)
Line 39: Line 32:
:*4: Channel 4 (medium text size)
:*4: Channel 4 (medium text size)
:*5: Channel 5 (unused) {{Not in FGD}}
:*5: Channel 5 (unused) {{Not in FGD}}
{{warning|Some HUDs may use Channel 0 and/or Channel 5.}}
{{KV|Master|intn=master|string|Legacy support: The name of a master entity. If the master hasn't been activated, this entity will not activate.}}
{{KV|Master|intn=master|string|Legacy support: The name of a master entity. If the master hasn't been activated, this entity will not activate.}}
{{KV Targetname}}
{{KV BaseEntity|noscroll=0}}
 
== Flags ==
== Flags ==
{{Fl|1|All Players}}
{{Fl|1|All Players|If this is not set, the message will only show to {{ent|!activator}}.}}


== Inputs ==
== Inputs ==
{{IO|Display|Display the message text.{{note|If the All Players flag is not set, the player must be the !activator of this input in order for the text to be shown.}}}}
{{IO|Display|Display the message text.{{note|If the All Players flag is not set, the player must be the {{ent|!activator}} of this input in order for the text to be shown.}}}}
{{IO|SetText|Set the text to display.|param=string|since={{as}}}}
{{IO|SetText|Set the text to display.|param=string|since={{as}}}}
{{tip|In older games, [[AddOutput]] <code>message</code> can be used to change text, although the <code>Display</code> input must be fired again.}}
{{tip|{{ent|AddOutput|message}} can be used to change text at runtime in older games which do not support <tt>SetText</tt>, although the <code>Display</code> input must be fired again.}}
{{IO|SetPosX|Set the X position of the text. (0 - 1.0 {{=}} left to right) (-1 centers)|param=float|since={{portal2}}}}
{{IO|SetPosX|Set the X position of the text. (0 - 1.0 {{=}} left to right) (-1 centers)|param=float|since={{portal2}}}}
{{IO|SetPosY|Set the Y position of the text. (0 - 1.0 {{=}} top to bottom) (-1 centers)|param=float|since={{portal2}}}}
{{IO|SetPosY|Set the Y position of the text. (0 - 1.0 {{=}} top to bottom) (-1 centers)|param=float|since={{portal2}}}}
{{IO|SetTextColor|Set color of the front text.|param=color255|since={{portal2}}}}
{{IO|SetTextColor|Set color of the front text.|param=color255|since={{portal2}}}}
{{IO|SetTextColor2|Set color of the transition text.|param=color255|since={{portal2}}}}
{{IO|SetTextColor2|Set color of the transition text.|param=color255|since={{portal2}}}}
{{I Targetname}}
{{I BaseEntity|noscroll=0}}


== Outputs ==
== Outputs ==
{{O Targetname}}
{{O Targetname}}


== See also ==
== See Also ==
* [[point_message]] - A similar entity that displays a small custom message at a specific position in the game world.
* {{ent|game_text_tf}} {{tf2|only}} - A similar entity that uses {{tf2|2}} fonts.
* [[Customizable triggered HUD-message]] - How to create a new entity that is similar to '''game_text''' but can receive the message string via a triggered input.
* {{ent|point_message}} - A similar entity that displays a small custom message at a specific position in the game world.
 
* [[Customizable triggered HUD-message]] - How to create a new entity that is similar to <tt>game_text</tt> but can receive the message string via a triggered input.
[[Category:GUI Entities]]
[[Category:GUI Entities]]

Revision as of 09:18, 7 October 2022

English (en)中文 (zh)Translate (Translate)

Template:Point ent

Entity Description

This entity displays text on players' screens. This text can be defined directly in the Hammer editor (unlike the similar env_message entity, which uses the titles.txt file). In multiplayer games, the text will normally only display for the activator of the "Display" input. The "All Players" flag can be ticked in order to display on the screens of all players.

Note.pngNote:If you are creating a mod with its own files and scripts, it's recommended to use the aforementioned env_message entity, which uses the titles.txt script for text parameters instead of keyvalues, allowing the text to be changed without having to recompile any maps. It also supports newlines and quotation marks, unlike regular game_text.
Tip.pngTip:Despite comments stating otherwise, game_text supports localized strings (e.g., #HL2_Chapter4_Title) in most or all Source games.
Warning.pngWarning:VMFs can become corrupted when using quotation marks (") in any entity's keyvalues or I/O, so quotation marks cannot be used in the Text Message field (not even \" characters). You can use two apostrophes ('') or detailed quotes (i.e., and ) instead.
Icon-Bug.pngBug:Doesn't work in Left 4 Dead 2 Left 4 Dead 2.  [todo tested in ?]
Icon-Bug.pngBug:Scales incorrectly for players that have game resolution higher than 1920x1080. Text will be much larger and some text will be hidden.
Todo: Is this Counter-Strike: Global Offensive only?
  [todo tested in ?]
C++ In code, it is represented by theCGameTextclass, defined in themaprules.cppfile.

Keyvalues

Message Text (message) <string>
Message to display onscreen. \n signifies a new line in the text.
Icon-Bug.pngBug:Hammer will automatically change \n to /n. This can be worked around by editing the VMF with a text editor, although it will need to be changed every time after each save.  [todo tested in ?]
X (0 - 1.0 = left to right) (-1 centers) (x) <string>
Horizontal position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the far left of the screen and 1 is the far right. -1 centers the text.
Y (0 - 1.0 = top to bottom) (-1 centers) (y) <string>
Vertical position on the player's screens to draw the text. The value should be between 0 and 1, where 0 is the top of the screen and 1 is the bottom. -1 centers the text.
Text Effect (effect) <choices>
Text scan effect
  • 0: Fade In/Out. The whole text is faded in, and then faded out.
  • 1: Credits
    Todo: Unknown—seems to act like Fade In/Out. Provide description.
  • 2: Scan Out. The text is scanned in letter by letter, and the whole text is then faded out.
Color1 (color) <color255>
The primary color used by all the text effects.
Note.pngNote:The color values seem to be added to the background, so either a bright white background or black text will cause the message to be invisible.
Note.pngNote:This keyvalue will default to black for entities not created in Hammer.
Color2 (color2) <color255>
The scanning color for the letter being scanned if the Text Effect keyvalue is set to Scan Out—usually a different shade of Color1.
Fade in Time (or character scan time) (fadein) <string>
The time it should take for the text to fully fade in.
Fade Out Time (fadeout) <string>
The time it should take for the text to fade out, after the hold time has expired.
Hold Time (holdtime) <string>
The time the text should stay onscreen, after fading in, before it begins to fade out.
Note.pngNote:This value defaults to zero for entities not created in Hammer.
Scan time (scan effect only) (fxtime) <string>
If the 'Text Effect' is set to Scan Out, this is the time it should take to scan out all the letters in the text.
Text Channel (channel) <choices>
You can have up to six individual game_text messages onscreen at once, stored in channels. Select which channel this text should be placed in, which will overwrite any active message already in that channel.
  • 0: Channel 0 (unused) !FGD
  • 1: Channel 1 (medium text size)
  • 2: Channel 2 (small text size)
  • 3: Channel 3 (large text size)
  • 4: Channel 4 (medium text size)
  • 5: Channel 5 (unused) !FGD
Warning.pngWarning:Some HUDs may use Channel 0 and/or Channel 5.
Master (master) <string>
Legacy support: The name of a master entity. If the master hasn't been activated, this entity will not activate.

Flags

All Players : [1]
If this is not set, the message will only show to !activator.

Inputs

Display
Display the message text.
Note.pngNote:If the All Players flag is not set, the player must be the !activator of this input in order for the text to be shown.
SetText <stringRedirectInput/string> (in all games since Alien Swarm)
Set the text to display.
Tip.pngTip:AddOutput message can be used to change text at runtime in older games which do not support SetText, although the Display input must be fired again.
SetPosX <floatRedirectInput/float> (in all games since Portal 2)
Set the X position of the text. (0 - 1.0 = left to right) (-1 centers)
SetPosY <floatRedirectInput/float> (in all games since Portal 2)
Set the Y position of the text. (0 - 1.0 = top to bottom) (-1 centers)
SetTextColor <color255RedirectInput/color32> (in all games since Portal 2)
Set color of the front text.
SetTextColor2 <color255RedirectInput/color32> (in all games since Portal 2)
Set color of the transition text.


Outputs

See Also