NPC
This is a list of all methods only available for NPCs. It is also possible to call Entity functions on NPCs.
Inherits methods from Entity.
Methods
Makes the NPC like, hate, feel neutral towards, or fear the entity in question. If you want to setup relationship towards a certain entity class, use NPC:AddRelationship.
NPCs do not see NextBots by default. This can be fixed by adding the FL_OBJECT flag to the NextBot.
NPC:AddRelationship( string relationstring )
Changes how an NPC feels towards another NPC. If you want to setup relationship towards a certain entity, use NPC:AddEntityRelationship.
Avoid using this in GM:OnEntityCreated to prevent crashing due to infinite loops. This function may create an entity with given class and delete it immediately after.
NPC:AdvancePath()
Advances the NPC on its path to the next waypoint.
NPC:AlertSound()
Force an NPC to play their Alert sound.
Executes any movement the current sequence may have.
NPC:CapabilitiesAdd( number capabilities )
Adds a capability to the NPC.
NPC:CapabilitiesClear()
Removes all of Capabilities the NPC has.
number NPC:CapabilitiesGet()
Returns the NPC's capabilities along the ones defined on its weapon.
NPC:CapabilitiesRemove( number capabilities )
Remove a certain capability.
NPC:ClearBlockingEntity()
Resets the NPC:GetBlockingEntity.
NPC:ClearCondition( number condition )
Clears out the specified COND enum on this NPC.
NPC:ClearEnemyMemory( Entity enemy = GetEnemy() )
Clears the Enemy from the NPC's memory, effectively forgetting it until met again with either the NPC vision or with NPC:UpdateEnemyMemory.
NPC:ClearExpression()
Clears the NPC's current expression which can be set with NPC:SetExpression.
NPC:ClearGoal()
Clears the current NPC goal or target.
NPC:ClearSchedule()
Stops the current schedule that the NPC is doing.
Translates condition ID to a string.
Returns the way the NPC "feels" about a given entity. See NPC:AddEntityRelationship.
For ai type entities, this will return ENTITY:GetRelationship. If it returns nil or for engine NPCs, this will return whatever was last set by NPC:AddEntityRelationship. As a last resort, engine will decide on the disposition based on this NPC's NPC:Classify.
Forces the NPC to drop the specified weapon.
NPC:ExitScriptedSequence()
Makes an NPC exit a scripted sequence, if one is playing.
NPC:FearSound()
Force an NPC to play its Fear sound.
NPC:FoundEnemySound()
Force an NPC to play its FoundEnemy sound.
Entity NPC:GetActiveWeapon()
Returns the weapon the NPC is currently carrying, or NULL.
number NPC:GetActivity()
Returns the NPC's current activity.
Vector NPC:GetAimVector()
Returns the aim vector of the NPC. NPC alternative of Player:GetAimVector.
number NPC:GetArrivalActivity()
Returns the activity to be played when the NPC arrives at its goal
Vector NPC:GetArrivalDirection()
Returns the direction from the NPC origin to its current navigational destination.
number NPC:GetArrivalDistance()
Returns NPC arrival distance, set by NPC:SetArrivalDistance.
number NPC:GetArrivalSequence()
Returns the sequence to be played when the NPC arrives at its goal.
number NPC:GetArrivalSpeed()
Returns NPC arrival speed, set by NPC:SetArrivalSpeed.
Returns the most dangerous/closest sound hint based on the NPCs location and the types of sounds it can sense.
Entity NPC:GetBlockingEntity()
Returns the entity blocking the NPC along its path.
number NPC:GetCurGoalType()
Returns the goal type for current navigation path.
number NPC:GetCurrentSchedule()
Returns the NPC's current schedule.
Returns how proficient (skilled) an NPC is with its current weapon.
Vector NPC:GetCurWaypointPos()
Gets the NPC's current waypoint position (where NPC is currently moving towards), if any is available.
Returns the entity that this NPC is trying to fight.
This returns nil if the NPC has no enemy. You should use IsValid (which accounts for nil and NULL) on the return to verify validity of the enemy. Issue Tracker: 3132
Returns the first time an NPC's enemy was seen by the NPC.
Returns the last known position of an NPC's enemy.
Similar to NPC:GetEnemyLastSeenPos, but the known position will be a few seconds ahead of the last seen position.
Returns the last seen position of an NPC's enemy.
Similar to NPC:GetEnemyLastKnownPos, but the known position will be a few seconds ahead of the last seen position.
Returns the last time an NPC's enemy was seen by the NPC.
string NPC:GetExpression()
Returns the expression file the NPC is currently playing.
Vector NPC:GetGoalPos()
Returns the position we are trying to reach, if any.
Entity NPC:GetGoalTarget()
Returns the entity we are trying to reach, if any.
number NPC:GetHullType()
Returns NPCs hull type set by NPC:SetHullType.
number NPC:GetIdealActivity()
Returns the ideal activity the NPC currently wants to achieve.
Returns the ideal move acceleration of the NPC.
number NPC:GetIdealMoveSpeed()
Returns the ideal move speed of the NPC.
number NPC:GetIdealSequence()
Returns the ideal sequence the NPC currently wants to achieve.
number NPC:GetIdealYaw()
Returns the ideal yaw (left right rotation) for this NPC at this moment.
table NPC:GetKnownEnemies()
Returns all known enemies this NPC has.
See also NPC:GetKnownEnemyCount
number NPC:GetKnownEnemyCount()
Returns known enemy count of this NPC.
See also NPC:GetKnownEnemies
Vector NPC:GetLastPosition()
Returns the last registered or memorized position of the NPC. When using scheduling, the NPC will focus on navigating to the last position via nodes.
See NPC:SetLastPosition.
Returns CurTime based time since this NPC last received damage from given enemy. The last damage time is set when NPC:MarkTookDamageFromEnemy is called.
number NPC:GetMaxLookDistance()
Returns NPCs max view distance. An NPC will not be able to see enemies outside of this distance.
number NPC:GetMinMoveCheckDist()
Returns how far should the NPC look ahead in its route.
Returns how far before the NPC can come to a complete stop.
number NPC:GetMoveDelay()
Returns the movement delay for given NPC.
See NPC:SetMoveDelay.
number NPC:GetMoveInterval()
Returns the current timestep the internal NPC motor is working on.
number NPC:GetMovementActivity()
Returns the NPC's current movement activity.
number NPC:GetMovementSequence()
Returns the index of the sequence the NPC uses to move.
Vector NPC:GetMoveVelocity()
Returns the current move velocity of the NPC.
number NPC:GetNavType()
Returns the NPC's navigation type.
NPC NPC:GetNearestSquadMember()
Returns the nearest member of the squad the NPC is in.
Vector NPC:GetNextWaypointPos()
Gets the NPC's next waypoint position, where NPC will be moving after reaching current waypoint, if any is available.
number NPC:GetNPCState()
Returns the NPC's state.
number NPC:GetPathDistanceToGoal()
Returns the distance the NPC is from Target Goal.
number NPC:GetPathTimeToGoal()
Returns the amount of time it will take for the NPC to get to its Target Goal.
Vector NPC:GetShootPos()
Returns the shooting position of the NPC, i. e. where their bullets would come from, etc.
If the NPC does not overwrite this, it will return Entity:GetPos.
number NPC:GetStepHeight()
Returns NPC step height.
Returns the NPC's current target set by NPC:SetTarget.
This returns nil if the NPC has no target. You should use IsValid (which accounts for nil and NULL) on the return to verify validity of the target. Issue Tracker: 3132
number NPC:GetTaskStatus()
Returns the status of the current task.
Returns CurTime based time since the enemy was reacquired, meaning it is currently in Line of Sight of the NPC.
Vector NPC:GetViewOffset()
Returns the view offset of the NPC. Set by NPC:SetViewOffset.
table NPC:GetWeapons()
Returns a table of the NPC's weapons.
Returns whether or not the NPC has the given condition.
Polls the enemy memory to check if the given entity has eluded us or not.
Polls the enemy memory to check if the NPC has any memory of given enemy.
boolean NPC:HasObstacles()
Returns true if the current navigation has an obstacle, this is different from NPC:GetBlockingEntity, this is for virtual navigation obstacles put by AI's local navigation system to prevent movement to the marked area, forcing NPC to steer around, for example.
NPC:IdleSound()
Force an NPC to play their Idle sound.
Makes the NPC ignore given entity/enemy until given time.
Returns whether or not the NPC is performing the given schedule.
boolean NPC:IsCurWaypointGoal()
Returns whether the current navigational waypoint is the final one.
boolean NPC:IsFacingIdealYaw()
Returns whether the NPC is facing their ideal yaw. See NPC:SetIdealYaw, NPC:GetIdealYaw and NPC:SetIdealYawAndUpdate.
boolean NPC:IsGoalActive()
Returns whether the NPC has an active goal.
Tests whether a position or an NPC is in the view cone of the NPC.
boolean NPC:IsMoveYawLocked()
Returns if the current movement is locked on the Yaw axis.
boolean NPC:IsRunningBehavior()
Checks if the NPC is running an ai_goal. ( e. g. An npc_citizen NPC following the Player. )
boolean NPC:IsSquadLeader()
Returns whether the current NPC is the leader of the squad it is in.
Returns true if the entity was remembered as unreachable. The memory is updated automatically from following engine tasks if they failed:
TASK_GET_CHASE_PATH_TO_ENEMY
TASK_GET_PATH_TO_ENEMY_LKP
TASK_GET_PATH_TO_INTERACTION_PARTNER
TASK_ANTLIONGUARD_GET_CHASE_PATH_ENEMY_TOLERANCE
SCHED_FAIL_ESTABLISH_LINE_OF_FIRE - Combine NPCs, also when failing to change their enemy
NPC:LostEnemySound()
Force an NPC to play their LostEnemy sound.
NPC:MaintainActivity()
Tries to achieve our ideal animation state, playing any transition sequences that we need to play to get there.
NPC:MarkEnemyAsEluded( Entity enemy = GetEnemy() )
Causes the NPC to temporarily forget the current enemy and switch on to a better one.
NPC:MarkTookDamageFromEnemy( Entity enemy = nil )
Marks the NPC as took damage from given entity.
See also NPC:GetLastTimeTookDamageFromEnemy.
number NPC:MoveClimbExec( Vector destination, Vector dir, number distance, number yaw, number left )
Executes a climb move.
Related functions are NPC:MoveClimbStart and NPC:MoveClimbStop.
Starts a climb move.
Related functions are NPC:MoveClimbExec and NPC:MoveClimbStop.
NPC:MoveClimbStop()
Stops a climb move.
Related functions are NPC:MoveClimbExec and NPC:MoveClimbStart.
number NPC:MoveJumpExec()
Executes a jump move.
Related functions are NPC:MoveJumpStart and NPC:MoveJumpStop.
NPC:MoveJumpStart( Vector vel )
Starts a jump move.
Related functions are NPC:MoveJumpExec and NPC:MoveJumpStop.
number NPC:MoveJumpStop()
Stops a jump move.
Related functions are NPC:MoveJumpExec and NPC:MoveJumpStart.
Makes the NPC walk toward the given position. The NPC will return to the player after amount of time set by player_squad_autosummon_time ConVar.
Only works on Citizens (npc_citizen) and is a part of the Half-Life 2 squad system.
The NPC must be in the player's squad for this to work.
NPC:MovePause()
Pauses the NPC movement?
Related functions are NPC:MoveStart, NPC:MoveStop and NPC:ResetMoveCalc.
NPC:MoveStart()
Starts NPC movement?
Related functions are NPC:MoveStop, NPC:MovePause and NPC:ResetMoveCalc.
NPC:MoveStop()
Stops the NPC movement?
Related functions are NPC:MoveStart, NPC:MovePause and NPC:ResetMoveCalc.
Works similarly to NPC:NavSetRandomGoal.
Creates a path to closest node at given position. This won't actually force the NPC to move.
See also NPC:NavSetRandomGoal.
Set the goal target for an NPC.
Creates a random path of specified minimum length between a closest start node and random node in the specified direction. This won't actually force the NPC to move.
Sets a goal in x, y offsets for the NPC to wander to
Forces the NPC to pickup an existing weapon entity. The NPC will not pick up the weapon if they already own a weapon of given type, or if the NPC could not normally have this weapon in their inventory.
Forces the NPC to play a sentence from scripts/sentences. txt
Makes the NPC remember an entity or an enemy as unreachable, for a specified amount of time. Use NPC:IsUnreachable to check if an entity is still unreachable.
NPC:RemoveIgnoreConditions( table conditions = nil )
Removes conditions to ignore for the this NPC.
NPC:ResetIdealActivity( number act )
Resets the ideal activity of the NPC. See also NPC:SetIdealActivity.
NPC:ResetMoveCalc()
Resets all the movement calculations.
Related functions are NPC:MoveStart, NPC:MovePause and NPC:MoveStop.
Starts an engine task.
Used internally by the ai_task.
NPC:SelectWeapon( string class )
Forces the NPC to switch to a specific weapon the NPC owns. See NPC:GetWeapons.
NPC:SentenceStop()
Stops any sounds (speech) the NPC is currently palying.
Equivalent to Entity:EmitSound( "AI_BaseNPC. SentenceStop" )
NPC:SetActivity( number act )
Sets the NPC's current activity.
NPC:SetArrivalActivity( number act )
NPC:SetArrivalDirection( Vector dir )
Sets the direction from the NPC origin to its current navigational destination.
NPC:SetArrivalDistance( number dist )
Sets the distance to goal at which the NPC should stop moving and continue to other business such as doing the rest of their tasks in a schedule.
NPC:SetArrivalSequence( number seq )
Sets the sequence to be played when the NPC arrives at its goal.
NPC:SetArrivalSpeed( number speed )
Sets the arrival speed? of the NPC
NPC:SetCondition( number condition )
Sets an NPC condition.
NPC:SetCurrentWeaponProficiency( number proficiency )
Sets the weapon proficiency of an NPC (how skilled an NPC is with its current weapon).
Sets the NPC's . vcd expression. Similar to Entity:PlayScene except the scene is looped until it's interrupted by default NPC behavior or NPC:ClearExpression.
Sets the Field Of View of the NPC, for use with such functions as NPC:IsInViewCone. it is also used internally by the NPC for enemy detection, etc.
NPC:SetHullSizeNormal()
Updates the NPC's hull and physics hull in order to match its model scale. Entity:SetModelScale seems to take care of this regardless.
NPC:SetHullType( number hullType )
Sets the hull type for the NPC.
NPC:SetIdealActivity( number )
Sets the ideal activity the NPC currently wants to achieve. This is most useful for custom SNPCs.
NPC:SetIdealSequence( number sequenceId )
Sets the ideal sequence the NPC currently wants to achieve. This is most useful for custom SNPCs.
NPC:SetIdealYaw( number angle )
Sets the ideal yaw angle (left-right rotation) for the NPC. Does not actually force the NPC to start turning in that direction. See NPC:UpdateYaw, NPC:GetIdealYaw and NPC:SetIdealYawAndUpdate.
Sets the ideal yaw angle (left-right rotation) for the NPC and forces them to turn to that angle.
Sets conditions to ignore, which would normally interrupt an Engine-based schedule. Specified conditions will still be set, will call ENTITY:OnCondition and can be returned by NPC:HasCondition, but they will no longer interrupt the Engine schedule.
NPC:SetLastPosition( Vector position )
Sets the last registered or memorized position for this NPC. When using scheduling, the NPC will focus on navigating to the last position via nodes.
The navigation requires ground nodes to function properly, otherwise the NPC could only navigate in a small area. (https://developer. valvesoftware. com/wiki/Info_node)
NPC:SetMaxLookDistance( number dist )
Sets NPC's max view distance. An NPC will not be able to see enemies outside of this distance.
NPC:SetMaxRouteRebuildTime( number time )
Sets how long to try rebuilding path before failing task.
NPC:SetMoveDelay( number delay )
Sets the movement delay for given NPC.
See NPC:GetMoveDelay.
NPC:SetMoveInterval( number time )
Sets the timestep the internal NPC motor is working on.
NPC:SetMovementActivity( number activity )
Sets the activity the NPC uses when it moves.
NPC:SetMovementSequence( number sequenceId )
Sets the sequence the NPC navigation path uses for speed calculation. Doesn't seem to have any visible effect on NPC movement.
NPC:SetMoveVelocity( Vector vel )
Sets the move velocity of the NPC
NPC:SetMoveYawLocked( boolean lock )
Sets whether the current movement should locked on the Yaw axis or not.
NPC:SetNavType( number navtype )
Sets the navigation type of the NPC.
NPC:SetNPCState( number state )
Sets the state the NPC is in to help it decide on a ideal schedule.
NPC:SetSchedule( number schedule )
Sets the NPC's current schedule.
Assigns the NPC to a new squad. A squad can have up to 16 NPCs. NPCs in a single squad should be friendly to each other.
See also ai. GetSquadMembers and NPC:GetSquad.
NPCs within the same squad are meant to function more effectively, tactics wise.
NPC:SetStepHeight( number height )
Sets the SNPC step height.
This only works for scripted NPCs.
NPC:SetTaskStatus( number status )
Sets the status of the current task.
Sets given entity as an unforgettable enemy.
NPC:SetViewOffset( Vector )
Sets the view offset of the NPC. Player alternative of Player:SetViewOffset.
This affects NPC's NPC:GetShootPos.
Forces the NPC to start an engine task, this has different results for every NPC.
NPC:StopMoving( boolean immediate = true )
Resets the NPC's movement animation and velocity. Does not actually stop the NPC from moving.
NPC:TargetOrder( Entity target )
Cancels NPC:MoveOrder basically.
Only works on Citizens (npc_citizen) and is a part of the Half-Life 2 squad system.
The NPC must be in the player's squad for this to work.
NPC:TaskComplete()
Marks the current NPC task as completed.
This is meant to be used alongside NPC:TaskFail to complete or fail custom Lua defined tasks. (Schedule:AddTask)
Marks the current NPC task as failed.
This is meant to be used alongside NPC:TaskComplete to complete or fail custom Lua defined tasks. (Schedule:AddTask)
Force the NPC to update information on the supplied enemy, as if it had line of sight to it.
NPC:UpdateTurnActivity()
Updates the turn activity. Basically applies the turn animations depending on the current turn yaw.
Forces the NPC to turn to their ideal yaw angle. See NPC:SetIdealYaw and NPC:SetIdealYawAndUpdate.
boolean NPC:UseActBusyBehavior()
This function only works on ai type SENTs.
boolean NPC:UseAssaultBehavior()
This function only works on ai type SENTs.
boolean NPC:UseFollowBehavior()
This function only works on ai type SENTs.
boolean NPC:UseFuncTankBehavior()
This function only works on ai type SENTs.
boolean NPC:UseLeadBehavior()
This function only works on ai type SENTs.
NPC:UseNoBehavior()
Undoes the other Use*Behavior functions.
This function only works on ai type SENTs.