Skip to content

NPCEntity

Overview

An NCPEntity represents an instance of an NPCType that is currently active in the game world.

See NPCList for information on how to access NPCEntities.

Info

An NPCEntity is a Proxy usertype, which means it is safe to copy and store in your scripts.
It cannot, however, be used with any persistent storage.

Warning

Use NPCEntity.isValid to confirm that an entity still exists before trying to access its properties.
Entities can be removed from the client by the server for various reasons, i.e. due to moving beyond the player view distance or death.
When an entity is removed it will become invalid, and any copies of this usertype should be disposed of.

If the same entity is re-added to the client by the server, such as walking back into visibility range, then a different new NPCEntity will be created.

Information available within an NPCEntity includes:

  • NPCType
  • UID
  • World position
  • Facing direction
  • TODO

Examples

-- Iterate all active NPCEntities
local allNPCs = NPCList.All()
for _,npcEntity in ipairs(allNPCs) do
    if npcEntity.config == config.NPC.HANS and npcEntity.coordGrid == CoordGrid._0_50_50_32_32 then
        -- Found Hans at a specific coord
    end
end

Constructors

Info

This usertype has no constructor, and you cannot create your own.

Properties

Info

All properties are read-only.

Name Type Description
isValid Boolean Whether this entity still exists.
Dispose of this usertype object when invalid.
uid Integer The unique ID (UID) of this entity.
displayName String The display name of this entity.
config NPCType The config used by this entity.
parentConfig NPCType The parent config used by this entity, if it is a MultiNPC.
configID Integer The ID of the config used by this entity.
parentConfigID Integer The ID of the parent config used by this entity, if it is a MultiNPC.
isMultiNPC Boolean Whether this NPCEntity is a MultiNPC.
position Vector3 The world position of this NPCEntity.
coordGrid CoordGrid Returns the CoordGrid tile this NPCEntity is currently on.
aabb AABB Returns the current bounding box for this NPCEntity.
facing Integer The current facing angle, in degrees, of this NPCEntity.
facingTarget Integer The target facing angle, in degrees, of this NPCEntity.
The NPCEntity will be turning towards this angle, if different from NPCEntity.facing.
route [ CoordGrid ] Returns a list of the current coordinates in the NPCEntity's movement route.
Returns the current position coordinate if the NPCEntity is not moving.
routeEnd CoordGrid? Returns the final coordinate in the NPCEntity's movement route.
Returns the current position coordinate if the NPCEntity is not moving.