Garry's Mod Wiki

NPC

This is a list of all methods only available for NPCs. It is also possible to call Entity functions on NPCs.

Methods

NPC:AddEntityRelationship( Entity target, number disposition, number priority )
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.
NPC:AlertSound()
Force an NPC to play his Alert sound.
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.
number NPC:Classify()
Returns the NPC class. Do not confuse with Entity:GetClass!
NPC:ClearCondition( number condition )
Clears out the specified Enums/COND 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.
string NPC:ConditionName( number cond )
Translates condition ID to a string.
number NPC:Disposition( Entity ent )
Returns the way the NPC "feels" about the entity.
NPC:DropWeapon( Weapon weapon = nil, Vector target = nil, Vector velocity = nil )
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 his 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
number NPC:GetArrivalSequence()
Returns the sequence to be played when the NPC arrives at its goal.
Entity NPC:GetBlockingEntity()
Returns the entity blocking the NPC along its path.
number NPC:GetCurrentSchedule()
Returns the NPC's current schedule.
number NPC:GetCurrentWeaponProficiency()
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.
NPC NPC:GetEnemy()
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
number NPC:GetEnemyFirstTimeSeen( Entity enemy = GetEnemy() )
Returns the first time an NPC's enemy was seen by the NPC.
Vector NPC:GetEnemyLastKnownPos( Entity enemy = GetEnemy() )
Returns the last known position of an NPC's enemy.
Vector NPC:GetEnemyLastSeenPos( Entity enemy = GetEnemy() )
Returns the last seen position of an NPC's enemy.
number NPC:GetEnemyLastTimeSeen( Entity enemy = GetEnemy() )
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.
number NPC:GetHullType()
Returns NPCs hull type set by NPC:SetHullType.
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: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. This only works properly when called on an NPC that can hold weapons, otherwise it will return the same value as Entity:GetPos.
Entity NPC:GetTarget()
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.
Weapon NPC:GetWeapon( string class )
Returns a specific weapon the NPC owns.
table NPC:GetWeapons()
Returns a table of the NPC's weapons.
Weapon NPC:Give( string weapon )
Used to give a weapon to an already spawned NPC.
boolean NPC:HasCondition( number condition )
Returns whether or not the NPC has the given condition.
boolean NPC:HasEnemyEluded( Entity enemy = GetEnemy() )
Polls the enemy memory to check if the given entity has eluded us or not.
boolean NPC:HasEnemyMemory( Entity enemy = GetEnemy() )
Polls the enemy memory to check if the NPC has any memory of given enemy.
NPC:IdleSound()
Force an NPC to play his Idle sound.
boolean NPC:IsCurrentSchedule( number schedule )
Returns whether or not the NPC is performing the given schedule.
boolean NPC:IsMoving()
Returns whether the NPC is moving or not.
boolean NPC:IsRunningBehavior()
Checks if the NPC is running an ai_goal. ( e.g. An npc_citizen NPC following the Player. )
boolean NPC:IsUnreachable( Entity testEntity )
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 his 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:MoveOrder( Vector position )
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.
boolean NPC:NavSetGoal( Vector pos, number length, Vector dir )
Works similarly to NPC:NavSetRandomGoal.
boolean NPC:NavSetGoalTarget( Entity target, Vector offset )
Set the goal target for an NPC.
boolean NPC:NavSetRandomGoal( number minPathLength, Vector dir )
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.
boolean NPC:NavSetWanderGoal( number xOffset, number yOffset )
Sets a goal in x, y offsets for the NPC to wander to
boolean NPC:PickupWeapon( Weapon wep )
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.
number NPC:PlaySentence( string sentence, number delay, number volume )
Forces the NPC to play a sentence from scripts/sentences.txt
NPC:RememberUnreachable( Entity ent, number time = 3 )
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:RemoveMemory()
We advise against using this. It may be changed or removed in a future update. This function crashes the game no matter how it is used and will be removed in a future update. Use NPC:ClearEnemyMemory instead.
NPC:RunEngineTask( number taskID, number taskData )
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: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: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).
NPC:SetEnemy( Entity enemy, boolean newenemy = true )
Sets the target for an NPC.
number NPC:SetExpression( string expression )
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.
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:SetIdealYawAndUpdate( number angle, number speed = -1 )
Sets the ideal yaw angle (left-right rotation) for the NPC and forces them to turn to that angle.
NPC:SetLastPosition( Vector Position )
Sets the last registered or memorized position for an 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:SetMaxRouteRebuildTime( number time )
Sets how long to try rebuilding path before failing task.
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: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.
NPC:SetTarget( Entity entity )
Sets the NPC's target. This is used in some engine schedules.
NPC:StartEngineTask( number task, number taskData )
Forces the NPC to start an engine task, this has different results for every NPC.
NPC:StopMoving()
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)
NPC:TaskFail( string task )
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)
NPC:UpdateEnemyMemory( Entity enemy, Vector pos )
Force the NPC to update information on the supplied enemy, as if it had line of sight to it.
boolean NPC:UseActBusyBehavior()
Only usable on "ai" base entities.
boolean NPC:UseFollowBehavior()
Only usable on "ai" base entities.
NPC:UseNoBehavior()
Undoes the other Use*Behavior functions. Only usable on "ai" base entities.

Page Links


Special Pages


Wikis

?

Render Time: 48ms

DB GetPage 3
Generate Html 6
SaveChanges (1) 19
Render Body 0
Render Sidebar 14