From Valve Developer Community
Revision as of 06:57, 1 August 2018 by Pinsplash (talk | contribs) (removed the {{PAGENAME}} only because that was an exceedingly dumb use of it)

Jump to: navigation, search

ai_relationship is a point entity available in all Source games.

Entity description

Ai relationship.png
It sets a relationship type between two parties. These parties can be an NPC, an NPC class, or the player(s).


Will not attack the target. Rebels follow automatically, and can be commanded. The player will lower his gun until the target shows signs of hostility (but can still shoot the target before this). Zombies will remain still and only turn to face the target.
Will not attack. Rebels avoid player apologetically, and cannot be commanded. Zombies will remain still and only turn to face the target.
Considers the target an enemy/enemies and will attack.
Avoids the target. Headcrabs run away without attacking. Metropolice attacks. Rebels avoid without attacking, and cannot be commanded. Zombies will occasionally also swipe at the target as if it is in their flight path, but these swipes will afflict no damage to player, unless the zombie has been attacked.


Subject(s) <targetname>
The targetname or class name (e.g. npc_zombie) of the NPCs whose disposition will change.
Target(s) <targetname>
The targetname or class name of the NPCs about whom the subject(s) will change their disposition.
Tip:Use !player for the player.
Disposition <choices>
The way the subject(s) should feel about the target(s)
  • Hate
  • Fear
  • Like
  • Neutral
Radius for subject <float>
Only NPCs within this distance of the entity will have their dispositions changed.
Disposition Priority <integer>
How much the subject(s) should Like/Hate/Fear the target(s). Higher priority = stronger feeling.
Start Active <boolean>
Apply this relationship as soon as the entity spawns?
Reciprocal <boolean>
Make the new disposition apply to the targets as well as the subjects.


Name <string>
The targetname that other entities refer to this entity by.
Entity Scripts <scriptlist> (New with Left 4 Dead 2)
Space delimited list of VScript files (without file extension) that are executed after all entities have spawned. The scripts are all executed in the same script scope, later ones overwriting any identical variables and functions.
Script think function <string> (New with Left 4 Dead 2)
Name of a function in this entity's script which will be called automatically every 100 milliseconds (ten times a second) for the duration of the script. It can be used to create timers or to simulate autonomous behavior. The return value (if present) will set the time until the next call.
Note:Try to avoid expensive operations in this function, as it may cause performance problems.


  • Notify subject of target's location
  • Notify target of subject's location


Apply relationship changes. This will change all subject entities' relationships to all target entities.
Note:Once you fire ApplyRelationship, the entity is on until you send a Disable or RevertRelationship input. During the time any entities that spawn who match the subject or target names will be affected.
Warning: Unpredictable results may occur when two ai_relationship entities refer to the same set or subset of target or subject entities. This situation should be avoided.
Revert relationship changes. This will return the relationship to what it was at the time the ApplyRelationship input was called (or when this ai_relationship was spawned if Start Active is set).
Revert relationship changes to the default relationship, which may have changed since this ai_relationship was applied. This returns control of the entity relationship to the code.


Removes this entity and any entities parented to it from the world.
Functions the same as Kill, although this entity and any entities parented to it are killed on the same frame, being marginally faster than Kill.
AddOutput <string>
Evaluates a keyvalue/output on this entity. It can be potentially very dangerous, use with care.
Format: <key> <value>
Format: <output name> <targetname>:<inputname>:<parameter>:<delay>:<max times to fire, -1 means infinite>
FireUser1 to FireUser4
Fire the OnUser outputs; see User Inputs and Outputs.
Use  !FGD
Same as a player invoking +use; may not do anything. Can also be invoked by creating an output that does not specify an input.
This input is not included in Valve's FGDs.
RunScriptFile <script> (New with Left 4 Dead 2)
Execute a VScript file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.
RunScriptCode <string> (New with Left 4 Dead 2)
Execute a string of VScript source code in the scope of the entity receiving the input. String quotation may be needed when fired via console.
Bug: In <Left 4 Dead 2>, the code is executed in the script scope of the entity that fires the output, not the one receiving the input.
Warning: Never try to pass string parameters to a script function with this input. It will corrupt the VMF structure because of the nested quotation marks, which then must be removed manually with a text editor.
CallScriptFunction <string> (New with Left 4 Dead 2) !FGD
Execute a VScript function in the scope of the receiving entity.
SetLocalOrigin <coordinates> (New with Alien Swarm) !FGD
Send this entity to a spot in the map. If the entity is parented to something, it will be offset from the parent by this amount.
SetLocalAngles <angles> (New with Alien Swarm) !FGD
Set this entity's angles.



OnUser1 to OnUser4
These Outputs each fire in response to the firing of the like-numbered FireUser1 to FireUser4 Input; see User Inputs and Outputs.
OnKilled  (Only in the Left 4 Dead series)
This Output fires when the entity is killed and removed from the game.

See also