From Valve Developer Community
Jump to: navigation, search

<Half-Life 2> ai_goal_police is a point entity available in the Half-Life 2 series.

Entity description

Ai goal police.png

Makes an npc_metropolice guard ("police") an area against a target entity. If the target comes within range, the officer will chase it out of range - administering weapon_stunstick beatings if necessary. Note that it is not required for standard metrocop player provocation/chase behavior.

Trigger it by sending the selected npc_metropolice a SetPoliceGoal input, with the ai_goal_police's targetname as a parameter.

This AI goal will override any AI relationships (so you will not have to use an ai_relationship to make the officer not attack the player just because npc_metropolice hates the player by default). However, behavior is influenced by whether the "Gordon pre-criminal" global has been set.

This entity is also in the code for [Portal]. Its functionality is not guaranteed.

In code, it is represented by class CAI_PoliceGoal, defined in ai_goal_police.cpp.

Police Behavior

The officer will walk to his post (located in the very center of the guard post area) and stand there facing the direction specified. If the specified Target (NPCs or the player) enters the guard post area, the officer will be provoked. If the officer doesn't have a stun stick, he will just give verbal warnings when provoked (other nearby officers may attack for the officer if they have a stun stick). If the officer has a stun stick, he will also activate it to warn the target, and will suppress (beat) those who dares to get within his reach. (This does damage.)

Before activating his stunstick (if equipped, not essential though), the officer will push the player back a number of times before holding it up, and finally activating it. If provoked enough, the officer will finally (by default) leave his post to give chase to the target until its out of the guard post area, after which he will return to his post (if he can find his way back to it).

Knock Outs

The officer can also use his stun stick to knock the player out in one hit if instructed to do so by the Knock-out target past crossing plane flag, or the EnableKnockOut input. The crossing plane runs perpendicular to this entity's Pitch Yaw Roll

If the player is knocked out, the whole screen will turn white so the player can't see anything, but he can still move around just as normal, so this needs to be combined with sending the OnKnockOut output to other entities to be realistic. (In HL2, the player normally wakes up outside the guard post area, presumably having been carried there.)

This does not function for NPCs, if you want this effect on citizens you would have to script it or something of similar effect.


  • 2: Knock-out target past crossing plane
While the police target is behind the crossing plane (defined by this entity's Pitch Yaw Roll) knock out behavior described above will be enabled for the officer.
  • 4: Do not leave post
The officer will not leave his post to chase the target, no matter how provoked he will be. This is very useful when guarding entrances, as the target may otherwise lure the officer away from it and then circle around him and get past him. (Multiple examples of use on d1_trainstation_02.)


Radius (policeradius) <float>
The radius of the area to police. If a target enters this area, the officer will be provoked.
Target (policetarget) <targetname>
Specifies what target to protect the area against. (!player is an option.) Must be specified.


Classname (classname) <string>
The classname defines the type of entity. Classnames can be changed using AddOutput, which will influence how the engine deals with the entity in certain circumstances.
Name (targetname) <string>
The name that other entities refer to this entity by.
Global Entity Name (globalname) <string>
Name by which this entity is linked to another entity in a different map. When the player transitions to a new map, entities in the new map with globalnames matching entities in the previous map will have the previous map's state copied over their state.
Parent (parentname) <targetname>
Specifies a movement parent. An entity will maintain its initial offset from its parent. An attachment point can be added to the end of the name, separated by a comma. Every entity can be parented, even point entities. Entities which are parented will be forced to transition to the next map, such as from a trigger_transition. Some entities which aren't intended to be parented may not function correctly. phys_constraint can be used as a workaround to parenting.
Origin (X Y Z) (origin) <coordinates>
The position of this entity's center in the world. Rotating entities typically rotate around their origin.
Pitch Yaw Roll (X Y Z) (angles) <angle>
This entity's orientation in the world. Pitch is rotation around the Y axis, yaw is the rotation around the Z axis, roll is the rotation around the X axis.
Note.png Note: This works on brush entities, although Hammer doesn't show the new angles.
Flags (spawnflags) <integer>
Toggles features of an entity, its specific number is determined by the combination of flags added.
Response Contexts (ResponseContext) <string>
Pre-defined response system contexts for this entity. Format is key:value,key:value,.... Contexts may be filtered.
Effects (effects) <integer> !FGD
Combination of effect flags to use.
Local Time (ltime) <float> !FGD
The local time of the entity, independent of the global clock. Used mainly for physics calculations.
Next Think (nextthink) <float> !FGD
Amount of time before the entity thinks again.
Hammer ID (hammerid) <integer> !FGD
The entity's Hammer ID. Mainly used by plugins and debugging commands, such as ent_keyvalue. Can be manually assigned with the "hammerid" or "id" keyvalue. Entities spawned at run-time are not assigned any Hammer ID.


Enables knock out behavior described above.
Disables knock out behavior described above.


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.
SetParent <string>
Move with this entity. See Entity Hierarchy (parenting).
SetParentAttachment <string>
Change this entity to attach to a specific attachment point on its parent. The entity will teleport so that the position of its root bone matches that of the attachment. Entities must be parented before being sent this input.
SetParentAttachmentMaintainOffset <string>
As above, but without teleporting. The entity retains its position relative to the attachment at the time of the input being received.
Removes this entity from the the movement hierarchy, leaving it free to move independently.
AddOutput <string>
Evaluates a keyvalue/output on this entity.
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.
DispatchEffect <string> (removed in <Left 4 Dead>) !FGD
Dispatches a special effect from the entity's origin. Removed and replaced entirely by the particle system since <Left 4 Dead>.
DispatchResponse <string> !FGD
Dispatches a response to the entity. See Response and Concept.
AddContext <string>
Adds to the entity's list of response contexts. Format is <key>:<value>.
RemoveContext <string>
Remove a context from this entity's list. The name should match the key of an existing context.
ClearContext <string>
Removes all contexts from this entity's list.


Fires the first time a policing officer warns a target.
Fires the second time a policing officer warns a target.
Fires when a policing officer warns a target for the last time.
Fires when a policing officer starts to suppress (ie. beat) a target.
Fires when a target has been knocked out.


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.