AddOutput: Difference between revisions
SirYodaJedi (talk | contribs) No edit summary |
(rewrite) |
||
Line 2: | Line 2: | ||
{{TabsBar|main=s2|base=AddOutput}} | {{TabsBar|main=s2|base=AddOutput}} | ||
{{cleanup|The primary purpose of AddOutput is to add outputs to an entity (like the name implies). The fact that a lot of keyvalues can be changed with AddOutput is just a happy side effect of how outputs are stored in compiled maps (where they're just KVs with special formmating); no Valve maps use it that way. This page should be updated accordingly, and other pages which report a KV being unable to be edited with AddOutput as a bug should change it to a note instead, as it isn't a bug (since it isn't intended behavior.}} | {{cleanup|The primary purpose of AddOutput is to add outputs to an entity (like the name implies). The fact that a lot of keyvalues can be changed with AddOutput is just a happy side effect of how outputs are stored in compiled maps (where they're just KVs with special formmating); no Valve maps use it that way. This page should be updated accordingly, and other pages which report a KV being unable to be edited with AddOutput as a bug should change it to a note instead, as it isn't a bug (since it isn't intended behavior.}} | ||
{{This is a|[[input]]|name=AddOutput}} | {{This is a|[[input]]|name=AddOutput}} Its primary purpose is registering additional actions for when entity's chosen output fires (usually referred to as simply adding an output). | ||
{{ | |||
AddOutput | Syntax: <code><output> <target>:[input]:[parameter_override]:[delay]:[times to fire (-1 or 0 = infinity, 1 = once, 2 = twice ...)]</code> | ||
* <> = mandatory parameter | |||
* [] = optional parameter | |||
* output - existing output on the given entity | |||
* target - [[targetname]] of the targeted entity (special targetnames like !caller, !activator, !self etc. are also supported) | |||
* input - input to be used on targeted entity (if left blank <code>Use</code> input us used) | |||
* parameter_override - parameter (if left blank and the given output holds a value then that will be automatically filled in) | |||
* delay - delay in seconds (left blank means 0) | |||
* times to fire - number of times this output can fire this action (left blank means -1) | |||
== Example == | |||
We have a {{ent|math_counter}} named <code>counter</code>. | |||
The following shows an output that could be setup on a {{ent|trigger_once}} in Hammer: | |||
<pre> | |||
My output named: OnStartTouch | |||
Target entities named: counter | |||
Via this input: AddOutput | |||
With a parameter override of: OutValue car:skin | |||
</pre> | |||
The following are equivalent | |||
* <code>OutValue car:skin</code> | |||
* <code>OutValue car:skin:::</code> | |||
* <code>OutValue car:skin::0:-1</code> | |||
The parameter_override is left blank which means it will be filled with value of math_counter's OutValue. | |||
{{Warning|In Hammer don't use quotation characters (") in any of the fields (not even <code>\"</code> characters). It will cause fatal errors with opening and/or compiling your map and may need to be fixed by manually editing the [[VMF]] in a text editor. Instead, use detailed quotes (i.e. <code>“</code> and <code>”</code>) or two apostrophes ( <nowiki>''</nowiki> ).}} | |||
== Using AddOutput to change keyvalues == | |||
Because of the way it's implemented AddOutput also allows changing any entity's keyvalues. This includes <kbd>targetname</kbd>, <kbd>rendercolor</kbd>, <kbd>solid</kbd> and more. As this is not a purpose for which AddOutput was implemented not all keys will work as expected when changed this way. | |||
Syntax: <code><key> <value></code> | |||
Due to how much AddOutput lets you manipulate entities properties it might be therefore a way to optimize maps which utilize {{ent|env_entity_maker}}, {{ent|point_teleport}}, {{ent|game_text}} and more which count as [[edict]]. | |||
{{Tip|Abusing AddOutput too much makes your map harder to understand. Avoid abusing it unless necessary for your use case.}} | {{Tip|Abusing AddOutput too much makes your map harder to understand. Avoid abusing it unless necessary for your use case.}} | ||
=== Examples of keyvalues whose change might not have desired effect === | |||
;classname | |||
:<kbd>classname</kbd> is first key read from a map file and determines what C++ class to use to spawn an entity, therefore changing this later via AddOutput will not truly change an entity into a different one. But there are sometimes checks in code that determine some behavior purely on the value of <code>classname</code> for example see [[Preserved entities]]. ({{todo}} some more example) | |||
:{{Warning|Doing this in games with save files is not advised as saving entity with wrong classname means it won't be recreated properly or at all}} | |||
:{{Warning|Changing the classname of a player causes problems and should be avoided at all costs.}} | |||
:{{Note|Certain entities rely upon classname, so this is generally discouraged.}} | |||
;parentname | |||
:Won't have an effect when changed via AddOutput as parent/child hierarchy is setup when all entities are being spawned and not later. | |||
;SourceEntityName of {{ent|ambient_generic}} | |||
:ambient_generic searches for the entity named <kbd>SourceEntityName</kbd> when it spawned so changing it later via AddOutput won't have an effect and this is usually a reason when any keyvalue change via AddOutput doesn't do what was expected | |||
== Limitations == | == Limitations == | ||
* It's not possible to add an output with this that uses [[Context|AddContext]] input because AddContext also uses ':' in its syntax. | * It's not possible to add an output with this that uses [[Context|AddContext]] input because AddContext also uses ':' in its syntax. | ||
* Since AddOutput uses a space in its syntax, outputs and keyvalues which have spaces cannot be modified. Fortunately, this is unlikely to ever be an issue, as no vanilla entities use spaces | |||
== Firing AddOutput via {{cmd|ent_fire}} == | == Firing AddOutput via {{cmd|ent_fire}} == | ||
Because AddOutput uses space in its syntax it's required to enclose the ent_fire parameter in quotes. | Because AddOutput uses space in its syntax it's required to enclose the ent_fire parameter in quotes. | ||
To add output: {{pre|ent_fire <entity name> addoutput "<OutputName> <target>:<input>:<parameter_override>:<delay>:<refires>"}} | |||
To change keyvalue: {{pre|ent_fire <entity name> addoutput "<key> <value>"}} | To change keyvalue: {{pre|ent_fire <entity name> addoutput "<key> <value>"}} | ||
== Examples == | == Examples == | ||
Line 85: | Line 117: | ||
Results in translucent player when standing in the trigger_multiple (OnStartTouch) and visible again when not in the trigger_multiple (OnEndTouch). | Results in translucent player when standing in the trigger_multiple (OnStartTouch) and visible again when not in the trigger_multiple (OnEndTouch). | ||
== See | == See alsо == | ||
*[https://rafuron.wordpress.com/2011/05/19/2nd-mapping-trick-templates-and-ent-limits/ Optimizing Edict's & Mapping Tricks] - Using AddOutput to reduce mapspawn [[edicts]] on really large maps | * [https://rafuron.wordpress.com/2011/05/19/2nd-mapping-trick-templates-and-ent-limits/ Optimizing Edict's & Mapping Tricks] - Using AddOutput to reduce mapspawn [[edicts]] on really large maps | ||
[[Category:IO System]] | [[Category:IO System]] |
Revision as of 05:18, 4 April 2025

AddOutput
is an input available in all Source games. Its primary purpose is registering additional actions for when entity's chosen output fires (usually referred to as simply adding an output).
Syntax: <output> <target>:[input]:[parameter_override]:[delay]:[times to fire (-1 or 0 = infinity, 1 = once, 2 = twice ...)]
- <> = mandatory parameter
- [] = optional parameter
- output - existing output on the given entity
- target - targetname of the targeted entity (special targetnames like !caller, !activator, !self etc. are also supported)
- input - input to be used on targeted entity (if left blank
Use
input us used) - parameter_override - parameter (if left blank and the given output holds a value then that will be automatically filled in)
- delay - delay in seconds (left blank means 0)
- times to fire - number of times this output can fire this action (left blank means -1)
Example
We have a math_counter named counter
.
The following shows an output that could be setup on a trigger_once in Hammer:
My output named: OnStartTouch Target entities named: counter Via this input: AddOutput With a parameter override of: OutValue car:skin
The following are equivalent
OutValue car:skin
OutValue car:skin:::
OutValue car:skin::0:-1
The parameter_override is left blank which means it will be filled with value of math_counter's OutValue.

\"
characters). It will cause fatal errors with opening and/or compiling your map and may need to be fixed by manually editing the VMF in a text editor. Instead, use detailed quotes (i.e. “
and ”
) or two apostrophes ( '' ).Using AddOutput to change keyvalues
Because of the way it's implemented AddOutput also allows changing any entity's keyvalues. This includes targetname, rendercolor, solid and more. As this is not a purpose for which AddOutput was implemented not all keys will work as expected when changed this way.
Syntax: <key> <value>
Due to how much AddOutput lets you manipulate entities properties it might be therefore a way to optimize maps which utilize env_entity_maker, point_teleport, game_text and more which count as edict.

Examples of keyvalues whose change might not have desired effect
- classname
- classname is first key read from a map file and determines what C++ class to use to spawn an entity, therefore changing this later via AddOutput will not truly change an entity into a different one. But there are sometimes checks in code that determine some behavior purely on the value of
classname
for example see Preserved entities. ([Todo] some more example) Warning:Doing this in games with save files is not advised as saving entity with wrong classname means it won't be recreated properly or at all
Warning:Changing the classname of a player causes problems and should be avoided at all costs.
Note:Certain entities rely upon classname, so this is generally discouraged.
- parentname
- Won't have an effect when changed via AddOutput as parent/child hierarchy is setup when all entities are being spawned and not later.
- SourceEntityName of ambient_generic
- ambient_generic searches for the entity named SourceEntityName when it spawned so changing it later via AddOutput won't have an effect and this is usually a reason when any keyvalue change via AddOutput doesn't do what was expected
Limitations
- It's not possible to add an output with this that uses AddContext input because AddContext also uses ':' in its syntax.
- Since AddOutput uses a space in its syntax, outputs and keyvalues which have spaces cannot be modified. Fortunately, this is unlikely to ever be an issue, as no vanilla entities use spaces
Firing AddOutput via ent_fire
Because AddOutput uses space in its syntax it's required to enclose the ent_fire parameter in quotes.
To add output:
ent_fire <entity name> addoutput "<OutputName> <target>:<input>:<parameter_override>:<delay>:<refires>"
To change keyvalue:
ent_fire <entity name> addoutput "<key> <value>"
Examples
- Format:
<key> <value>
{ "classname" "trigger_once" . . . 'OnStartTouch" "game_text,AddOutput,message There is a fire ahead. Go the other way!,0,1 'OnStartTouch" "game_text,Display,,0.02,1 }
This changes the text of a game_text and then displays it. This is useful as to prevent having an unneccesary amount of game_text which counts as edict
- Format:
<output> <targetname>:<input>:<parameter>:<delay>:<refire>
{ "classname" "tf_logic_auto" . . . 'OnMapSpawn" "team_round_timer_red,AddOutput,OnFinished game_round_win:RoundWin::0:-1,0,-1 }
This adds an output to an entity with the targetname "team_round_timer_red".
- Trigger_Multiple
- Name: Ghost
- Outputs
- My Output Named: OnEndTouch
- Targets entities named: !activator
- Via this input: Alpha
- With a parameter override of: 255
- After a delay in seconds: 0.10
- My Output Named: OnStartTouch
- Targets entities named: !activator
- Via this input: AddOutput
- With a parameter override of: rendermode 1
- After a delay in seconds: 0.00
- My Output Named: OnStartTouch
- Targets entities named: !activator
- Via this input: Alpha
- With a parameter override of: 120
- After a delay in seconds: 0.00
Results in translucent player when standing in the trigger_multiple (OnStartTouch) and visible again when not in the trigger_multiple (OnEndTouch).
See alsо
- Optimizing Edict's & Mapping Tricks - Using AddOutput to reduce mapspawn edicts on really large maps