Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.

Entity changes

Saul Rennison edited this page Apr 24, 2022 · 3 revisions

An entity is any object in the game that is not part of the world (i.e. walls, floors and other static surfaces). For example, players, weapons, grenades and physics props are entities. Every entity has an index, which can be used to access it. Entities are typically referred to by index in game events and user messages (except players, which are typically referred to by user ID - see below).

Given an entity index, you can access it using:

demoFile.entities.entities.get(index);

All entities have a server class - this defines the properties that it has. Server class names always start with a C, e.g. CWeaponUSP. A server class contains one or more data tables. Data table names usually start with DT_, e.g. DT_BaseCombatWeapon. These data tables contain the actual properties, referred to as send props. A complete list of server classes and data tables can be found in the sendtabletypes documentation.

Worked example

Imagine you want to track each time a weapon has its silencer attached or removed. First you need to find the name of the entity property that represents this. You can do this by searching the API documentation for "silencer" - this reveals DT_WeaponCSBase.m_bSilencerOn. You can then use the change event to monitor whenever an entity property changes:

demoFile.entities.on("change", e => {
  for (const change of e.changes) {
    if (
      change.tableName === "DT_WeaponCSBase" &&
      change.varName === "m_bSilencerOn"
    ) {
      var attached = change.newValue ? "attached" : "removed";
      console.log(
        `${e.entity.owner.name} ${attached} the silencer on their ${e.entity.itemName}`
      );
    }
  }
});

On any given entity, you can access its properties directly through the getProp method. If you are using TypeScript, autocompletion should be available.

In the demofile library, many entity properties are provided through user-friendly helper members. This means you rarely have to read entity properties directly. In the previous example, notice how we used Weapon#owner and Weapon#itemName to introspect the weapon. There are many other helpers available, so be sure to check the API documentation.

Player entities

There are several ways in which players are referred to in demo files:

Identifier Description Usage in demofile
Entity index A number in the range of [1..maxPlayers].
If a player disconnects, the entity index could be re-used by another player joining the game.
demoFile.entities.entities.get(entityIndex)
Client slot Same as entityIndex - 1.
If a player disconnects, the slot could be re-used by another player joining the game.
demoFile.entities.entities.get(entityIndex - 1)
User ID Identifier that is guaranteed to uniquely refer to the same player in a given demo file.
If a player disconnects, the same user ID will never be re-used by another player joining the game.
demoFile.entities.getByUserId(userId)

Clone this wiki locally