Targetname: Difference between revisions
Thunder4ik (talk | contribs) m (clean up, replaced: {{ModernBug → {{bug (3)) |
Thunder4ik (talk | contribs) m (Unicodifying) |
||
Line 1: | Line 1: | ||
{{langsp}} | {{langsp}} | ||
{{KV info|Targetname}} | {{KV info|Targetname}} | ||
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 [[ | 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 [[Inputs and Outputs|I/O System]]. | ||
== Notes == | |||
* Entities may also be targeted by their [[classname]] (e.g. <code>prop_dynamic</code>). | * Entities may also be targeted by their [[classname]] (e.g. <code>prop_dynamic</code>). | ||
* 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 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 <code>!</code> or <code>*</code> characters (see below). | * Targetnames cannot contain <code>!</code> or <code>*</code> characters (see below). | ||
* Targetnames also cannot contain <code>,</code> characters if you intend to use the entity as a parent, as this is used to set an [[attachment point]]. | * Targetnames also cannot contain <code>,</code> characters if you intend to use the entity as a parent, as this is used to set an [[attachment point]]. | ||
== Instances == | |||
* [[Instance]]s may use prefix or postfix name fixups, and will auto-generate a prefix if no parameters are specified. | * [[Instance]]s 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'''. | * Prefixes and Postfixes are separated by a single dash e.g. '''hall_a3-door_02'''. | ||
* Placing an <code>@</code> 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'''. | * Placing an <code>@</code> 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. | In most multiplayer games, any entity with the following targetnames will have a [[Use]] input sent to them when that event occurs. | ||
* <code>game_playerdie</code> - Fires every time a {{ent|player}} dies. The player who died is the '''<code>!activator</code>'''. | * <code>game_playerdie</code> - Fires every time a {{ent|player}} dies. The player who died is the '''<code>!activator</code>'''. | ||
Line 19: | Line 19: | ||
* <code>game_playerleave</code> - Fires every time a {{ent|player}} leaves the game. '''<code>!activator</code>''' will not work in this case, as the <code>player</code> entity no longer exists. | * <code>game_playerleave</code> - Fires every time a {{ent|player}} leaves the game. '''<code>!activator</code>''' will not work in this case, as the <code>player</code> entity no longer exists. | ||
{{confirm|In what games do game_playerjoin and game_playerspawn actually work?}} | {{confirm|In what games do game_playerjoin and game_playerspawn actually work?}} | ||
{{tip|In {{tf2}}{{l4d2}}, use [[ | {{tip|In {{tf2}}{{l4d2}}, use [[Team Fortress 2/Scripting/Script Functions#Hooks|VScript event hooks]] which also offer extra information with each event (such as the attacker on death etc). Equivalent event names are <code>player_spawn</code>, <code>player_death</code> and <code>player_disconnect</code>.}} | ||
== 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 {{ent|filter_activator_name}}/<code>[[filter_activator_class|class]]</code> or an entity's [[ | 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 {{ent|filter_activator_name}}/<code>[[filter_activator_class|class]]</code> or an entity's [[parent]] field. The extended features are: | ||
*Wildcards | *Wildcards | ||
Line 29: | Line 29: | ||
::{{note|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|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.}} | ||
The [[ | The [[Inputs and Outputs|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. | ||
{{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 == | |||
The following special targetnames can be used to dynamically select an entity. | The following special targetnames can be used to dynamically select an entity. | ||
Line 38: | Line 38: | ||
; <code>!activator</code> | ; <code>!activator</code> | ||
: The entity that began the current I/O chain. | : The entity that began the current I/O chain. | ||
: If a player walks into a [[ | : 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). | ||
; <code>!self</code> | ; <code>!self</code> | ||
: The entity from which the current input originates. | : The entity from which the current input originates. | ||
Line 57: | Line 57: | ||
{{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.}} | ||
{{bug|In Portal 2, entities parented using the <code>parentname</code> parameter fail to parent on map startup.}} | {{bug|In Portal 2, entities parented using the <code>parentname</code> parameter fail to parent on map startup.}} | ||
:{{workaround|Use a [[ | :{{workaround|Use a [[logic auto]] and a <code>SetParent</code> input instead.}} | ||
; <code>!player_blue</code>{{Portal2|only}} | ; <code>!player_blue</code>{{Portal2|only}} | ||
: In Portal 2 Coop, this targets ATLAS (player 1). | : In Portal 2 Coop, this targets ATLAS (player 1). | ||
Line 68: | Line 68: | ||
: In multiplayer games, it uses the first player that joined the server. | : In multiplayer games, it uses the first player that joined the server. | ||
=== FindNamedEntity Keywords === | |||
These keywords are only available in <code>FindNamedEntity</code>, 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. | These keywords are only available in <code>FindNamedEntity</code>, 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|{{Game link|Mapbase}} makes this available to I/O searches. Is this the case in any other branch?}} | : {{todo|{{Game link|Mapbase}} makes this available to I/O searches. Is this the case in any other branch?}} | ||
; <code>!speechtarget</code> | ; <code>!speechtarget</code> | ||
: The entity at which the <code>!caller</code> is looking due to a [[Choreography creation/Creating Events/Other Events# | : The entity at which the <code>!caller</code> is looking due to a [[Choreography creation/Creating Events/Other Events#Look at Actor|Look At Actor]] or [[Choreography creation/Creating Events/Other Events#Face Actor|Face Actor]] choreography event. | ||
; <code>!friend</code> | ; <code>!friend</code> | ||
: The <code>!caller</code>'s nearest friendly NPC. This returns the player on NPCs which don't descend from <code>CAI_PlayerAlly</code>. | : The <code>!caller</code>'s nearest friendly NPC. This returns the player on NPCs which don't descend from <code>CAI_PlayerAlly</code>. | ||
Line 79: | Line 79: | ||
: 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}}. | * 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. | * When an output's "Target Entity" is empty, <code>!self</code> is ''not'' set to the <code>!caller</code> value. |
Revision as of 15:06, 7 January 2024
Targetname is a
base
Keyvalue available in all 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.
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
.game_playerspawn
- Fires every time a player spawns, with the spawning player as the!activator
.Bug:
game_playerspawn
does not function in. [todo tested in ?]
game_playerleave
- Fires every time a player leaves the game.!activator
will not work in this case, as theplayer
entity no longer exists.




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:
Mapbase has support for complex wildcard matching like *_door, area*_door, ar*a*_d*r,
?
wildcards, etc.Note: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.
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.

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

!activator
- The entity that began the current I/O chain.
- If a player walks into a trigger that fires a logic_relay, the player is the
!activator
of the relay's output(s). !self
- The entity from which the current input originates.
- If a player walks into a trigger that fires a logic_relay, the relay is the
!self
of its output(s).
- If a logic_relay fires
ForceSpawnAtEntityOrigin !self
to an env_entity_maker withOnTrigger
, the!self
entity is the env_entity_maker itself.
!caller
- The entity from which the current output originates.
- If a player walks into a trigger that fires a logic_relay, the trigger is the
!caller
of the relay's output(s).
- If a logic_relay fires
ForceSpawnAtEntityOrigin !caller
to an env_entity_maker withOnTrigger
, the!caller
entity is the relay itself. - For entities such as
filter_activator_[xxxx]
or logic_case, the!caller
of aTestActivator
orPickRandom/PickRandomShuffle
is thefilter_activator_[xxxx]
/logic_case
itself, not the entity that fired the input.
Note:Individual inputs can override the entity targeted by
!caller
! This is done by point_entity_finder, math_counter, logic_case, and filter entities.!player
- Targets the player.
- In multiplayer games, it targets the first player that joined the server.


player
classname.
parentname
parameter fail to parent on map startup. [todo tested in ?]Workaround:Use a logic auto and a
SetParent
input instead.!player_blue
(only in)
- In Portal 2 Coop, this targets ATLAS (player 1).
!player_orange
(only in)
- In Portal 2 Coop, this targets P-Body (player 2).
!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.
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 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 fromCAI_PlayerAlly
. !enemy
- The current enemy of the
!caller
.
Keyword Notes
- Both
!activator
and!caller
can be different for specific inputs, which depends on each input's implementation. In most cases this is in an undesired manner, likeGetValue
for math_counter. - When an output's "Target Entity" is empty,
!self
is not set to the!caller
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
- User Inputs and Outputs
GetDebugName()
, for accessing an entity's targetname in C++.