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
Line 42: Line 42:
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. IO events hold additional information about so called '''activator''' and '''caller''' and this is set up by how a specific output was fired.  
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. IO 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''').  
Usually the '''activator''' is the entity that caused the output to fire. Examples:
* OnPressed output of {{ent|func_button}} when fired will set the player that pressed it as the '''activator'''
* OnStartTouch output of {{ent|trigger_multiple}} when fired will set the entity that touched it as the '''activator'''  
 
And '''caller''' is very often the entity where the output is defined, but there are rare cases where this differs and the output sets something else as '''caller'''.
Examples of specials cases:
* 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
* OnReachedFloor output of {{ent|info_elevator_floor}} sets '''caller''' as func_elevator entity that reached the given floor
* OnFoundEntity output of {{ent|point_entity_finder}} sets '''caller''' as the found entity


And '''caller''' is very often 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}}
{{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}}

Revision as of 01:24, 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. IO 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. Examples:

  • OnPressed output of func_button when fired will set the player that pressed it as the activator
  • OnStartTouch output of trigger_multiple when fired will set the entity that touched it as the activator

And caller is very often the entity where the output is defined, but there are rare cases where this differs and the output sets something else as caller. Examples of specials cases:

  • 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
  • OnReachedFloor output of info_elevator_floor sets caller as func_elevator entity that reached the given floor
  • OnFoundEntity output of point_entity_finder sets caller as the found entity


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.