Ai goal police: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (add AI category)
No edit summary
 
(64 intermediate revisions by 21 users not shown)
Line 1: Line 1:
[[category:AI]]
{{LanguageBar}}
ai_goal_police
{{CD|CAI_PoliceGoal|base=CBaseEntity|file1=ai_goal_police.cpp}}
{{this is a|point entity|name=ai_goal_police|game=Half-Life 2 series|sprite=1}}


AI Goal Police
==Entity description==
Makes an {{ent|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 {{ent|weapon_stunstick}} beatings if necessary. Note that it is ''not'' required for standard metrocop player provocation/chase behavior.


KEYS
Trigger it by sending the selected <code>npc_metropolice</code> a [[npc_metropolice#Inputs|<code>SetPoliceGoal</code> input]], with the <code>ai_goal_police</code>'s [[targetname]] as a parameter.


Name targetname <target_source> The name that other entities refer to this entity by.
This AI goal will override any AI relationships (so you will not have to use an {{ent|ai_relationship}} to make the officer not attack the player just because <code>npc_metropolice</code> hates the player by default). However, behavior is influenced by whether the "Gordon pre-criminal" [[env_global|global]] has been set.


Parent parentname <target_destination> The name of this entity's parent in the movement hierarchy. Entities with parents move with their parent.
{{stray ent|{{portal|4}}}}


Pitch Yaw Roll (Y Z X) 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.


spawnflags spawnflags <flags>
===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''' ([[:Category:NPCs|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.)


Radius policeradius <float> Radius to police
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).


Target policetarget <string> Target to police
===Knock Outs===
The officer can also use their 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 <code>EnableKnockOut</code> 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 they can't see anything, but can still move around just as normal, so this needs to be combined with sending the <code>OnKnockOut</code> output to other entities in order to be realistic. (In HL2, the player normally wakes up outside the guard post area, presumably having been carried there.)


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


Kill Removes this entity from the world.
==Flags==
<!--This entity does not have a "one" flag. Don't know why. -Pinsplash-->
*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 {{ent|d1_trainstation_02}}.)


KillHierarchy Removes this entity and all its children from the world.
==Keyvalues==
{{KV Targetname}}
{{KV|Radius|intn=policeradius|float|The radius of the area to police. If a target enters this area, the officer will be provoked.}}
{{KV|Target|intn=policetarget|target_destination|Specifies what target to protect the area against. ({{ent|!player}} is an option.) Must be specified.}}


AddOutput <string> Adds an entity I/O connection to this entity. Format: <output name> <targetname>:<inputname>:<parameter>:<delay>:<max times to fire (-1 == infinite)>. Very dangerous, use with care.
==Inputs==
{{I|EnableKnockOut|Enables knock out behavior described above.}}
{{I|DisableKnockOut|Disables knock out behavior described above.}}


FireUser1 Causes this entity's OnUser1 output to be fired.
==Outputs==
{{O|OnFirstWarning|Fires the first time a policing officer warns a target.}}
{{O|OnSecondWarning|Fires the second time a policing officer warns a target.}}
{{O|OnLastWarning|Fires when a policing officer warns a target for the last time.}}
{{O|OnSupressingTarget|Fires when a policing officer starts to suppress (ie. beat) a target.}}
{{O|OnKnockOut|Fires when a target has been knocked out.}}


FireUser2 Causes this entity's OnUser2 output to be fired.
[[Category:AI]]
 
FireUser3 Causes this entity's OnUser3 output to be fired.
 
FireUser4 Causes this entity's OnUser4 output to be fired.
 
SetParent <string> Changes the entity's parent in the movement hierarchy.
 
SetParentAttachment <string> Change this entity to attach to a specific attachment point on its parent. Entities must be parented before being sent this input. The parameter passed in should be the name of the attachment.
 
ClearParent Removes this entity from the the movement hierarchy, leaving it free to move independently.
 
EnableKnockOut Tells the goal to make the active policing NPC knock out its target
 
DisableKnockOut Stop the active policing NPC from trying to knock out its target
 
 
OUTPUTS
 
OnUser1 Fired in response to FireUser1 input.
 
OnUser2 Fired in response to FireUser2 input.
 
OnUser3 Fired in response to FireUser3 input.
 
OnUser4 Fired in response to FireUser4 input.
 
OnFirstWarning Fires the first time a policing cop warns a target
 
OnSecondWarning Fires the second time a policing cop warns a target
 
OnLastWarning Fires when a policing cop warns a target for the last time
 
OnSupressingTarget Fires when a policing cop starts to suppress (ie. beat) a target
 
OnKnockOut Fires when a target has been knocked out

Latest revision as of 18:07, 1 June 2025

English (en)Translate (Translate)
C++ Class hierarchy
CAI_PoliceGoal
CBaseEntity
C++ ai_goal_police.cpp
Ai goal police.png

ai_goal_police is a point entity available in Half-Life 2 series 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.

Note.pngNote:This entity is also in the code for Portal Portal. Its functionality is not guaranteed.


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 their 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 they can't see anything, but can still move around just as normal, so this needs to be combined with sending the OnKnockOut output to other entities in order 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 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

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

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.

Inputs

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

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.