CAI BaseNPC

From Valve Developer Community
Jump to: navigation, search
class hierarchy
CAI_BaseNPC defined in ai_basenpc.cpp
CBaseCombatCharacter
CBaseFlex
CBaseAnimatingOverlay
CBaseAnimating
CBaseEntity
Icon-Important.pngImportant:Following Keyvalues / Inputs / Outputs are available for all entities that inherit this class

Keyvalues

BaseNPC keyvalues
Relationship (???) <string> !FGD
Changes whether this NPC likes or dislikes certain others. Used like the ai_relationship entity, with this NPC as the subject. Format: <string|targetname or classname> <string|disposition> <int|rank>.
Values for disposition are:
  • D_HT: Hate
  • D_FR: Fear
  • D_LI: Like
  • D_NU: Neutral
Target Path Corner (target) <targetname>
The path_corner that this NPC will move to after spawning.
Squad Name (squadname) <string>
NPCs that are in the same squad (i.e., have matching squad names) will share information about enemies and will take turns attacking and covering each other.
Hint Group (hintgroup) <string>
Hint groups are used by NPCs to restrict their hint-node searching to a subset of the map's hint nodes. Only hint nodes with matching hint group names will be considered by this NPC.
Hint Limit Nav (hintlimiting) <boolean>
Limits NPC to using specified hint group for navigation requests. Does not limit local navigation.
Sleep State (sleepstate) <choices>
Holds the NPC in stasis until specified condition. See also Wake Radius and Wake Squad.
  • 0: None
  • 1: Waiting for threat
  • 2: Waiting for PVS
  • 3: Waiting for input, ignore PVS
  • 4: Auto PVS
  • 5: Auto PVS after PVS
Wake Radius (wakeradius) <float>
Auto-wake if player comes within this distance.
Wake Squad (wakesquad) <boolean>
Wake all of the NPCs squadmates if the NPC is woken.
Enemy Filter (enemyfilter) <targetname>
Filter entity to test targets against.
Ignore unseen enemies (ignoreunseenenemies) <boolean>
Prefers visible enemies, regardless of distance or relationship priority.
Physics Impact Damage Scale (physdamagescale) <float>
Scales damage energy when this character is hit by a physics object. With a value of 0 the NPC will take no damage from physics.

DamageFilter:

Damage Filter (damagefilter) <targetname>
Name of the filter_damage_type entity that controls which entities can damage us.

Inputs

BaseNPC inputs
AddHealth <integer> (in all games since Half-Life 2: Episode Two)
RemoveHealth <integer> (in all games since Half-Life 2: Episode Two)
Add to or remove from the NPC's health.
SetHealth <integer>
Set the NPC's health.
Break
Smash into pieces. If this is not possible, disappear.
BecomeRagdoll  (in all games since Half-Life 2: Episode Two)
Remove itself and instantly become a ragdoll with zero force (just go limp). OnDeath, etc. outputs will NOT be fired.
ForceInteractionWithNPC <string> <string>  (in all games since Half-Life 2: Episode One)
Force the NPC to use a dynamic interaction with another NPC. Syntax is <targetname> <dynamic interaction>.
ForgetEntity <targetname>
Clears out the NPC's knowledge of a named entity.
UpdateEnemyMemory  (in all games since Half-Life 2: Episode One)
Update (or create) this NPC's memory of of the given entity.
GagEnable
GagDisable
Gagged NPCs won't speak (or moan, caw, etc.) unless made to be a choreographed scene.
HolsterWeapon  (in all games since Half-Life 2: Episode One)
UnholsterWeapon  (in all games since Half-Life 2: Episode One)
Force the NPC to holster or unholster their weapon. Ignored if the NPC is scripting or if the NPC doesn't use weapons.
HolsterAndDestroyWeapon  (in all games since Half-Life 2: Episode One)
Same as HolsterWeapon, except the weapon is destroyed once it has been concealed.
IgnoreDangerSounds <float>
Ignore danger sounds for the specified number of seconds.
physdamagescale <float>
Scales the damage taken when this character is hit by a physics object. 0 means this feature is disabled for backwards compatibility.
SetBodyGroup <integer>
HACK: Sets this NPC's body group (from 0–n).
SetMaxLookDistance <float> (only in Garry's Mod)
Sets the maximum look distance for the NPC. Defaults are 2048 and 6000 for long range NPCs.
SetRelationship <string|targetname or classname> <string|disposition> <int|rank>
Changes whether this NPC likes or dislikes certain others. Used like the ai_relationship entity, with this NPC as the subject.
Values for disposition are:
  • D_HT: Hate
  • D_FR: Fear
  • D_LI: Like
  • D_NU: Neutral
SetSquad <string>
Change the name of this NPC's squad. Leaving the parameter blank will remove the NPC from any existing squad.
StartScripting
StopScripting
Enter/exit scripting state, where NPCs ignore a variety of stimulus that would make them break out of their scripts. They ignore danger sounds, ignore +Use, don't idle speak or respond to other NPCs' idle speech, and so on.
Wake
Wakes up the NPC if it is sleeping.

DamageFilter:

SetDamageFilter <string>
Sets the entity to use as damage filter. Pass in an empty string (no parameter) to clear the damage filter.

Flags

BaseNPC flags
  •  [1] : Wait Till Seen
       Prevents this NPC from seeing (or being seen) until it enters a player's viewcone.
  •  [2] : Gag
       Won't make IDLE sounds until it's angry.
  •  [4] : Fall to ground (unchecked means teleport to ground)
  •  [8] : Drop Healthkit
       Causes this NPC to drop an item_healthvial upon dying.
  •  [16] : Efficient
       Don't acquire enemies or avoid obstacles
  •  [128] : Wait For Script
       Forces this NPC to "wait" in an idle state until it finishes playing a scripted_sequence.
  •  [256] : Long Visibility/Shoot
       By default, increases a NPC's sight range to 6,000 units and allows it to attack from anywhere within that distance.
  •  [512] : Fade Corpse
  •  [1024] : Think outside PVS
       Allows this NPC to run its regular AI outside of any player's PVS.
  •  [2048] : Template NPC
       Marks this NPC as a template for entities like npc_template_maker. The NPC will not spawn on its own. This is not needed for point_template.
  •  [4096] : Do Alternate collision for this NPC (player avoidance)
    Note.pngNote:This flag is disabled in Half-Life 2: Episode One Half-Life 2: Episode Two episodic for player companions, because the StartScripting input does this.
  •  [8192] : Don't drop weapons
  •  [16384] : Ignore player push (in all games since Source 2006)
       Entity won't give way to player.

Outputs

BaseNPC Outputs
OnDamaged
Fired when this NPC takes damage (!activator is the damage inflictor).
OnDamagedByPlayer
Fired when this NPC is hurt by a player (!activator is the attacker or vehicle driver [if friendly fire]).
OnDamagedByPlayerSquad
Fired when this NPC is hurt by a player OR by one of the player's squadmates (!activator is the attacker or vehicle driver [if friendly fire]).
OnDeath
Fired when this NPC is killed (!activator is the killer).
OnDenyCommanderUse
Fired when this NPC has refused to join the player's squad.
OnForcedInteractionAborted
Fired when the NPC aborts a forced interaction for some reason (target NPC died, couldn't be pathed to, etc.).
OnForcedInteractionStarted
Fired when the NPC starts a forced interaction.
OnForcedInteractionFinished
"NPCs in actbusies can no longer perform dynamic interactions."
Blank image.pngTodo: What does this mean?
OnHalfHealth
Fired when this NPC reaches half of its maximum health.
OnHearCombat
Fired when this NPC hears combat sounds.
OnHearPlayer
Fired when this NPC hears the player.
OnHearWorld
Fired when this NPC hears a sound (other than combat or the player).
OnFoundEnemy <targetname>
Fired when this NPC establishes line of sight to its enemy.
OnLostEnemy
Fired when this NPC loses its enemy. Usually due to the enemy being killed/removed, or because this NPC has selected a newer, more dangerous enemy.
OnLostEnemyLOS
Fired when this NPC loses line of sight to its enemy.
OnFoundPlayer <targetname>
Fired when this NPC establishes line of sight to its enemy, and that enemy is a player.
OnLostPlayer
Fired when this NPC loses its enemy, and that enemy was a player. Usually due to the enemy being killed/removed, or because this NPC has selected a newer, more dangerous enemy.
OnLostPlayerLOS
Fired when this NPC loses line of sight to its enemy, and that enemy is a player.
OnSleep
Fired when this NPC enters a sleep state.
OnWake
Fired when this NPC comes out of a sleep state.