Skip to content

NPC

NPC is a type of Entity which provides features for a non-player controlled humanoid character mode in the game. NPC derives from Entity and CharacterBase so if you have an NPC you can do any of these functions as well as the functions in Entity or CharacterBase. You can do entity:IsA(NPC) to see if a particular entity variable is an NPC type entity.

Functions

Function Name Usage Description Notes
Roll nPC:Roll() Trigger a roll in the direction the NPC is moving. Will roll forwards when the NPC is stationary. Server Only
Jump nPC:Jump() Make the NPC jump. This may also trigger a mantle if the NPC is in a position to do so. NPC mantling works the same way as Player Character mantling. Server Only
SetCrouching nPC:SetCrouching(bool shouldCrouch) Set the crouch state of the NPC. Server Only
SetLookAtEntity nPC:SetLookAtEntity(CharacterBase characterToLookAt) Set a CharacterBase as the look at focus for this NPC. The NPC will continuously rotate to face the target until the focus is changed or cleared. This will focus on the Head of the target CharacterBase. Only one focus may be set, this will override any previous entity or position focus. This will also override the facing of an NPC during movement, allowing for NPCs to look and move in different directions. Server Only
SetLookAtEntity nPC:SetLookAtEntity(CharacterBase characterToLookAt, string socket) Set a CharacterBase as the look at focus for this NPC. The NPC will continuously rotate to face the target until the focus is changed or cleared. Use the Socket parameter to focus on a specific socket on the target. Only one focus may be set, this will override any previous entity or position focus. This will also override the facing of an NPC during movement, allowing for NPCs to look and move in different directions. Server Only
SetLookAtEntity nPC:SetLookAtEntity(Entity entityToLookAt) Set an entity as the look at focus for this NPC. The NPC will continuously rotate to face the target until the focus is changed or cleared. Only one focus may be set, this will override any previous entity or position focus. This will also override the facing of an NPC during movement, allowing for NPCs to look and move in different directions. Server Only
GetLookAtEntity unhandled/AActor nPC:GetLookAtEntity() Get the entity this NPC is focused on; this will be the entity passed into SetLookAtEntity. Server Only
SetLookAtPosition nPC:SetLookAtPosition(Vector position) Set a world position as the look at focus for this NPC. The NPC will continuously rotate to face this position until the focus is changed or cleared. Only one focus may be set, this will override any previous entity or position focus. Server Only
GetLookAtPosition Vector nPC:GetLookAtPosition() Returns the focus position of this NPC. If a focus has been manually set this will either be the value set using SetLookAtPosition, or the a position calculated from the position of the Entity set using SetLookAtEntity. Alternatively if the NPC is moving using the MoveToPosition command it will return the position the NPC is moving towards. Server Only
GetLookAt Vector nPC:GetLookAt() Returns two values, the position of the NPC and the position the NPC is looking at. Server Only
ClearLookAt nPC:ClearLookAt() Clear the current NPC look at focus. Server Only
MoveToPosition nPC:MoveToPosition(Vector targetPosition) Instruct the NPC to move to the specified world vector. This does not utilise any pathfinding or obstacle avoidance; the NPC will move in a straight line towards the target position. It will not automatically use any special movement actions like Jump, Crouch or Mantle. The NPC will stop moving once it has reached the target position. Server Only
MoveToPosition nPC:MoveToPosition(Vector targetPosition, number movementMode) Instruct the NPC to move to the specified world vector. This does not utilise any pathfinding or obstacle avoidance; the NPC will move in a straight line towards the target position. It will not automatically use any special movement actions like Jump, Crouch or Mantle. The NPC will stop moving once it has reached the target position. This overload includes a 'MovementMode' parameter to specify the MovementMode the NPC should use. 1 = Walk, 2 = Run, 3 = Sprint Server Only
MoveToPosition nPC:MoveToPosition(Vector targetPosition, callback completionCallback) Instruct the NPC to move to the specified world vector. This does not utilise any pathfinding or obstacle avoidance; the NPC will move in a straight line towards the target position. It will not automatically use any special movement actions like Jump, Crouch or Mantle. The NPC will stop moving once it has reached the target position. The completion callback function will be called when the movement completes or is cancelled for any reason. Callback contains 1 bool parameter which will be true if the NPC successfully reached it's target; False otherwise. Server Only
MoveToPosition nPC:MoveToPosition(Vector targetPosition, callback completionCallback, number movementMode) Instruct the NPC to move to the specified world vector. This does not utilise any pathfinding or obstacle avoidance; the NPC will move in a straight line towards the target position. It will not automatically use any special movement actions like Jump, Crouch or Mantle. The NPC will stop moving once it has reached the target position. This overload includes a 'MovementMode' parameter to specify the MovementMode the NPC should use. 1 = Walk, 2 = Run, 3 = Sprint The completion callback function will be called when the movement completes or is cancelled for any reason. Callback contains 1 bool parameter which will be true if the NPC successfully reached it's target; False otherwise. Server Only
CancelMovement nPC:CancelMovement() Cancel the current NPC movement Server Only
PlayEmote nPC:PlayEmote(EmoteAsset emoteAsset) Play the specified emote on the NPC. Server Only
IsPlayingEmote bool nPC:IsPlayingEmote() Returns true if an emote is currently playing on the NPC. Server Only
CancelEmote nPC:CancelEmote() Cancel any emote that is currently playing. Server Only

Overrides

Override Name Usage Description Notes
new_index nPC.var = object value