This article's documentation is for anything that uses the Source engine. Click here for more information.

Targetname: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(→‎Keywords: rewrite attempt)
Line 36: Line 36:
{{tip|Although not feasible for some situations, most implementations of [[VScript]] support standalone entity iteration and contain string comparison tools, regex, etc., allowing for virtually any type of name matching.}}
{{tip|Although not feasible for some situations, most implementations of [[VScript]] support standalone entity iteration and contain string comparison tools, regex, etc., allowing for virtually any type of name matching.}}


== Keywords ==
== Special targetnames <span id="Keywords" \> ==
The following special targetnames can be used to dynamically select an entity.
The following special targetnames can be used to dynamically select an entity.  


{{note|Not all entity parameters can evaluate these targetnames. For example SetParent input can evaluate <code>!activator</code> parameter but player's SetFogController input is not able to evaluate <code>!activator/!caller</code> and needs to use the desired env_fog_controller's targetname.}}
=== Concept of activator / caller ===
{{note|Entity pages can specify how !caller/!activator is evaluated for each output. It is shown as small grey text under the name of the output and specifies what entity is targetted when using <kbd>!activator</kbd> or <kbd>!caller</kbd> as output's 'Target Entity'. (See for example [[prop_physics#Outputs]], [[math_counter#Outputs]] pages). {{wikinote|Specifying activator/caller for outputs can be done using [[Template:O]]'s parameters}}}}
Every output when fired creates an IO event added to the event queue (printable by {{cmd|dumpeventqueue}}), which is processed at proper time based on specified delay. Events hold additional information about so called '''activator''' and '''caller''' and this is set up by how a specific output was fired. Usually the '''activator''' is the entity that caused the output to fire (example OnPressed output when fired will set-up the player that pressed func_button as the '''activator'''). And caller is usually the entity where the output is defined but there are rare cases where this differs and the output sets something else as '''caller''' (example OnGetValue output of math_counter will set its '''caller''' as the the entity that was the '''caller''' of GetValue input which caused the output to fire).
 
{{wikinote|Entity pages can specify who the activator and caller is evaluated for each output. It is shown as small grey text under the name of the output. (See for example [[prop_physics#Outputs]], [[math_counter#Outputs]] pages). Specifying activator/caller for outputs can be done using [[Template:O]]'s parameters}}
 
 
=== When used as 'Target entity' ===
; <code>!caller</code> / <code>!self</code>
: These special targets will simply target the '''caller''' of the output making them equivalent in this context.
 
=== When used as an input parameter ===
{{note|As input parameters are processed in the entity accepting the input not all inputs can evaluate these targetnames. For example SetParent input can evaluate them but {{ent|player}}'s SetFogController input isn't able to do so and needs to use the desired env_fog_controller's targetname.}}


; <code>!activator</code>
: (Supposed to be) the entity that began the current I/O chain.
: &nbsp;&nbsp;If a player walks into a [[trigger multiple|trigger]] that fires a {{ent|logic_relay}}, the player is the <code>!activator</code> of the relay's output(s).
: Not all entities have this set as one would expect.
; <code>!self</code>
; <code>!self</code>
: The entity from which the current input originates.  
: The entity that is accepting the input.
: &nbsp;&nbsp;If a player walks into a trigger that fires a logic_relay, the relay is the <code>!self</code> of its output(s).{{ExpandBox|
: {{example|If a logic_relay fires <code>ForceSpawnAtEntityOrigin !self</code> to an {{ent|env_entity_maker}} with <code>OnTrigger</code>, the <code>!self</code> entity is the env_entity_maker itself.}}
* If a logic_relay fires <code>ForceSpawnAtEntityOrigin !self</code> to an env_entity_maker with <code>OnTrigger</code>, the <code>!self</code> entity is the env_entity_maker itself.
 
|Special case:}}
; <code>!caller</code>
; <code>!caller</code>
: (Supposed to be) the entity from which the current output originates.
: '''Caller''' of the output from which this input is coming from.
: If a player walks into a trigger that fires a logic_relay, the trigger is the <code>!caller</code> of the relay's output(s).
: {{Example|If a logic_relay fires <code>ForceSpawnAtEntityOrigin !caller</code> to an env_entity_maker with <code>OnTrigger</code>, the <code>!caller</code> entity is the relay itself.}}
: Not all entities have this set as one would expect.{{ExpandBox|
 
* If a logic_relay fires <code>ForceSpawnAtEntityOrigin !caller</code> to an env_entity_maker with <code>OnTrigger</code>, the <code>!caller</code> entity is the relay itself.
=== Behaves the same as both ===
* For entities such as <code>filter_activator_[xxxx]</code> or {{ent|logic_case}}, the <code>!caller</code> of a <code>TestActivator</code> or <code>PickRandom/PickRandomShuffle</code> is the <code>filter_activator_[xxxx]</code>/<code>logic_case</code> itself, not the entity that fired the input.
; <code>!activator</code>
|Special case:}}
: Entity that was the '''activator''' of the output. Can be thinked of as the entity that began the current I/O chain.
: {{note|Individual inputs can override the entity targeted by <code>!caller</code>! This is done by {{ent|point_entity_finder}}, {{ent|math_counter}}, {{ent|logic_case}}, and filter entities.}}
: {{example| OnStartTouch output of {{ent|trigger_multiple}} it's the entity that touched the trigger whether used as 'Target entity' or an input's parameter}}
 
; <code>!player</code>
; <code>!player</code>
: Targets the player.
: Targets the player.
: &nbsp;&nbsp;In multiplayer games, it targets the first player that joined the server.
: &nbsp;&nbsp;In multiplayer games, it targets the first player that joined the server.
{{note|When testing an entity's name, this behaves as expected, matching if the entity is a player.}}
:{{tip|To target all players in a server, use the <code>player</code> classname.}}
{{tip|To target all players in a server, use the <code>player</code> classname.}}
 
; <code>!player_blue</code>{{Portal2|only}}
: In Portal 2 Coop, this targets ATLAS (player 1).
; <code>!player_orange</code>{{Portal2|only}}
: In Portal 2 Coop, this targets P-Body (player 2).
; <code>!pvsplayer</code>
; <code>!pvsplayer</code>
: The first player found in the entity's [[Potential Visibility Set]]. The PVS used is taken from the entity doing the searching, or the activator if no searching entity exists. If no activator exists either, the first player in the game is returned (i.e. <code>!player</code>).
: The first player found in the entity's [[Potential Visibility Set]]. The PVS used is taken from the entity doing the searching, or the activator if no searching entity exists. If no activator exists either, the first player in the game is returned (i.e. <code>!player</code>).
; <code>!picker</code>
; <code>!picker</code>
: The first entity under the player's crosshair; mostly only for debugging. Entities without collision can only be selected by aiming at their origin.
: The first entity under the player's crosshair; mostly only for debugging. Entities without collision can only be selected by aiming at their origin.
: &nbsp;&nbsp;In multiplayer games, it uses the first player that joined the server.
: &nbsp;&nbsp;In multiplayer games, it uses the first player that joined the server.
; <code>!player_blue</code>{{Portal2|only}}
: In Portal 2 Coop, this targets ATLAS (player 1).
; <code>!player_orange</code>{{Portal2|only}}
: In Portal 2 Coop, this targets P-Body (player 2).


=== FindNamedEntity Keywords ===
=== FindNamedEntity Keywords ===
Line 84: Line 92:
; <code>!enemy</code>
; <code>!enemy</code>
: The current enemy of the <code>!caller</code>.
: The current enemy of the <code>!caller</code>.
=== Keyword Notes ===
* Both <code>!activator</code> and <code>!caller</code> can be different for specific inputs, which depends on each input's implementation. In most cases this is in an undesired manner, like <code>GetValue</code> for {{ent|math_counter}}.
* When an output's "Target Entity" is empty, <code>!self</code> is ''not'' set to the <code>!caller</code> value.
* Targetnames used in an output's parameter override field are evaluated by the entity that ''receives'' the output, not the one that sends it.


== See also ==
== See also ==

Revision as of 00:58, 26 April 2025

English (en)Hrvatski (hr)中文 (zh)Translate (Translate)
edit

targetname is a keyvalue available in all Source Source games. A targetname (also known simply as Name) is the name of an entity. A targetname is not required for an entity to exist, but generally must be present for an entity to play a part in the I/O System.

Notes

  • Entities may also be targeted by their classname (e.g. prop_dynamic).
  • Targetnames do not need to be unique, they can be shared (and inputs will be sent to each one). Duplicated targetnames are displayed in bold font.
  • Targetnames cannot contain ! or * characters (see below).
  • Targetnames also cannot contain , characters if you intend to use the entity as a parent, as this is used to set an attachment point.
  • Naming certain entities, such as lights, can alter their behavior.

Instances

  • Instances may use prefix or postfix name fixups, and will auto-generate a prefix if no parameters are specified.
  • Prefixes and Postfixes are separated by a single dash e.g. hall_a3-door_02.
  • Placing an @ symbol at the beginning of a targetname (e.g. @exit_door) will bypass a naming fixup for that particular entity. If @exit_door and exit_door_relay were part of an instance prefixed as Door_01, the names of the entities would be @exit_door and Door_01-exit_door_relay.

Player Events

In most multiplayer games, any entity with the following targetnames will have a Use input sent to them when that event occurs.

  • game_playerdie - Fires every time a player dies. The player who died is the !activator.
  • game_playerkill - Fires every time a player kills another player, the killer is the !activator.
  • game_playerjoin - Fires every time a player joins the game, the joining player is the !activator.
    Icon-Bug.pngBug:game_playerjoin is not fired by bots.  [todo tested in ?]
  • game_playerspawn - Fires every time a player spawns, with the spawning player as the !activator.
    Icon-Bug.pngBug:game_playerspawn does not function in Counter-Strike: SourceCounter-Strike: Global OffensiveTeam Fortress 2.
  • game_playerleave - Fires every time a player leaves the game. !activator will not work in this case, as the player entity no longer exists.
Confirm:In what games do game_playerjoin and game_playerspawn actually work?
Tip.pngTip:In Team Fortress 2Left 4 Dead 2, use VScript event hooks which also offer extra information with each event (such as the attacker on death etc). Equivalent event names are player_spawn, player_death and player_disconnect.

Name Matching

While searching for an entity, Source can use a few extended matching features that are useful in a variety of situations. They are used to target an entity with an unknown or partially known name, and they are most commonly used in I/O chains, but they can also be used in KeyValues which target entities, like the filter KV in filter_activator_name/class or an entity's parent field. The extended features are:

  • Wildcards
Source supports * wildcards to a limited extent. This means searching for area1* will match any targetnames that start with area1, like area1_portal or area1_door, but not area2_door. These wildcards are also limited to trailing *, which means more complex wildcards like *_door or area*_door will not function.
Note.pngNote:Hammer does not recognize most of these forms of matching and will see them as errors in the editor, but they will work in-game.
Note.pngNote:Mapbase Mapbase has support for complex wildcard matching like *_door, area*_door, ar*a*_d*r, ? wildcards, etc.

The I/O System also supports classname matching, which matches by an entity's classname rather than its targetname. This uses all of the same extended matching features listed above. Some other parts of Source support classname matching, but this usually isn't the case unless stated otherwise.

Icon-Important.pngImportant:It's not possible to target by targetname and classname at once. If some entity has targetname prop_window for example and we want to target all entities where classname starts with prop_ by doing ent_fire prop_* kill the prop_* will first try matching all targetnames and will only use classname if entity with no such targetname is found making classname matching unreliable. Likewise if some entity is named player and we try to target all players by using their classname player it won't work as the entity named player would be the target.
Tip.pngTip:Although not feasible for some situations, most implementations of VScript support standalone entity iteration and contain string comparison tools, regex, etc., allowing for virtually any type of name matching.

Special targetnames

The following special targetnames can be used to dynamically select an entity.

Concept of activator / caller

Every output when fired creates an IO event added to the event queue (printable by dumpeventqueue), which is processed at proper time based on specified delay. Events hold additional information about so called activator and caller and this is set up by how a specific output was fired. Usually the activator is the entity that caused the output to fire (example OnPressed output when fired will set-up the player that pressed func_button as the activator). And caller is usually the entity where the output is defined but there are rare cases where this differs and the output sets something else as caller (example OnGetValue output of math_counter will set its caller as the the entity that was the caller of GetValue input which caused the output to fire).

Wiki Note:Entity pages can specify who the activator and caller is evaluated for each output. It is shown as small grey text under the name of the output. (See for example prop_physics#Outputs, math_counter#Outputs pages). Specifying activator/caller for outputs can be done using Template:O's parameters


When used as 'Target entity'

!caller / !self
These special targets will simply target the caller of the output making them equivalent in this context.

When used as an input parameter

Note.pngNote:As input parameters are processed in the entity accepting the input not all inputs can evaluate these targetnames. For example SetParent input can evaluate them but player's SetFogController input isn't able to do so and needs to use the desired env_fog_controller's targetname.
!self
The entity that is accepting the input.
PlacementTip.pngExample:If a logic_relay fires ForceSpawnAtEntityOrigin !self to an env_entity_maker with OnTrigger, the !self entity is the env_entity_maker itself.
!caller
Caller of the output from which this input is coming from.
PlacementTip.pngExample:If a logic_relay fires ForceSpawnAtEntityOrigin !caller to an env_entity_maker with OnTrigger, the !caller entity is the relay itself.

Behaves the same as both

!activator
Entity that was the activator of the output. Can be thinked of as the entity that began the current I/O chain.
PlacementTip.pngExample: OnStartTouch output of trigger_multiple it's the entity that touched the trigger whether used as 'Target entity' or an input's parameter
!player
Targets the player.
  In multiplayer games, it targets the first player that joined the server.
Tip.pngTip:To target all players in a server, use the player classname.
!pvsplayer
The first player found in the entity's Potential Visibility Set. The PVS used is taken from the entity doing the searching, or the activator if no searching entity exists. If no activator exists either, the first player in the game is returned (i.e. !player).
!picker
The first entity under the player's crosshair; mostly only for debugging. Entities without collision can only be selected by aiming at their origin.
  In multiplayer games, it uses the first player that joined the server.
!player_blue(only in Portal 2)
In Portal 2 Coop, this targets ATLAS (player 1).
!player_orange(only in Portal 2)
In Portal 2 Coop, this targets P-Body (player 2).

FindNamedEntity Keywords

These keywords are only available in FindNamedEntity, a method specific to NPCs which is only searched by specific systems (e.g. choreographed scenes) and not by things like the I/O System.

Todo: Mapbase Mapbase makes this available to I/O searches. Is this the case in any other branch?
!speechtarget
The entity at which the !caller is looking due to a Look At Actor or Face Actor choreography event.
!friend
The !caller's nearest friendly NPC. This returns the player on NPCs which don't descend from CAI_PlayerAlly.
!enemy
The current enemy of the !caller.

See also


Stub

This article or section is a stub. You can help by expanding it.