ai_goal_police

From Valve Developer Community
Jump to: navigation, search
Ai goal police.png

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

Entity description

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 theCAI_PoliceGoalclass, defined in theai_goal_police.cppfile.

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.

Flags

  • 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.)

Keyvalues

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.

Base:
Name (targetname) <string>
The name that other entities use to refer to this entity.
Parent (parentname) <targetname>
Maintain the same initial offset to this entity. An attachment point can also be used if separated by a comma at the end. (parentname [targetname],[attachment])
Tip.pngTip:Entities transition to the next map with their parents
Tip.pngTip:phys_constraint can be used as a workaround if parenting fails.
Origin (X Y Z) (origin) <coordinates>
The position of this entity's center in the world. Rotating entities typically rotate around their origin.
Note.pngNote:Hammer does not move the entities accordingly only in the editor.
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.pngNote:This works on brush entities, although Hammer doesn't show the new angles.
Classname (classname) <string> !FGD
Determines the characteristics of the entity before it spawns.
Tip.pngTip:Changing this on runtime still has use, like making matching an entry in S_PreserveEnts will persist the entity on new rounds!
Flags (spawnflags) <integer> !FGD
Toggles exclusive features of an entity, its specific number is determined by the combination of flags added.
Effects (effects) <integer> !FGD
Combination of effect flags to use.

Inputs

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

Base:
AddContext <string>
Adds to the entity's list of response contexts. See Context.
AddOutput <string>
Assigns a new keyvalue/output on this entity. For keyvalues, some rely on extra necessary code to be ran and won't work if its simply just changed through this input. There is a strict format that must be followed:
// Format of changing KeyValues: "AddOutput [key] [value]"
//// Raw text:
"OnUser1" "!self,AddOutput,targetname new_name"

// Format of adding an Output: "AddOutput {targetname}:{inputname}:{parameter}:{delay}:{max times to fire, -1 means infinite}"
//// Raw text:
"OnUser1" "!self,AddOutput,OnUser1:SetParent:!activator:0.0:-1"
// Arguments can be left blank, but the empty blank should still be contained.
//// Raw text:
"OnUser1" "!self,AddOutput,OnUser1:ClearParent::0.0:-1"
ClearContext
Removes all contexts from this entity's list.
ClearParent
Removes this entity from the the movement hierarchy, leaving it free to move independently.
FireUser1 to FireUser4
Fires the respectiveOnUseroutputs; see User Inputs and Outputs.
Kill
Removes this entity and any entities parented to it from the world.
KillHierarchy
Functions the same as Kill, although this entity and any entities parented to it are killed on the same frame, being marginally faster thanKillinput.
RemoveContext <string>
Remove a context from this entity's list. The name should match the key of an existing context.
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.
Use  !FGD
Same as a player invoking +use; no effect in most cases.
DispatchResponse <string> !FGD
Dispatches a response to the entity. See Response and Concept.
DispatchEffect <string> (removed since Left 4 Dead) !FGD
Dispatches a special effect from the entity's origin; See also List of Client Effects. Replaced by the particle system since Left 4 Dead.

Outputs

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

Base:

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.