Skip to Content

entitylist

Find entities: local pawn and controller, lookups by handle or index, class lists, pawns, controllers and game rules.


Most entity operations require an active game session. Check engine.is_in_game() before using game-only functionality. Every function returns entities (base_entity_t); a lookup that finds nothing returns nil.

FunctionReturns
entitylist.local_pawn()The local player's pawn (the local controller's m_hPawn), or nil.
entitylist.local_controller()The local player's controller, or nil.
entitylist.handle(handle)The entity handle names, or nil. A handle is index and serial together (e:handle()): once the entity is gone, its handle resolves to nil even after another entity takes the same index.
entitylist.index(index)The entity living at entity index index now, or nil.
entitylist.list(class?, include_inherits?)A Lua table (array) of entities in index order. See below.
entitylist.game_rules()table_t exposing C_CSGameRules fields, or nil.
entitylist.pawns(enemies_only?, include_dead?)A Lua table (array) of player pawns (C_CSPlayerPawn) in index order. See below.
entitylist.controllers(enemies_only?, include_dead?)A Lua table (array) of player controllers in index order. See below.

entitylist.list

entitylist.list()
entitylist.list(class)
entitylist.list(class, include_inherits)

Without class, every entity. class is an exact schema class name, such as C_CSPlayerPawn, CCSPlayerController or C_CSWeaponBase. Set include_inherits = true to also match every class that derives from class, directly or through any of its base classes, as the game's schema records them: entitylist.list('C_BaseModelEntity', true) returns pawns, weapons, grenades and every other model entity. This argument is strictly boolean; omitted or false matches the exact class only. Each distinct class is checked once per call, not once per entity.

The result is a plain Lua table: iterate it with ipairs, count it with #. It is a snapshot; entities created or removed later are not reflected.

entitylist.pawns and entitylist.controllers

entitylist.pawns(enemies_only?, include_dead?)
entitylist.controllers(enemies_only?, include_dead?)

One pass over the entity list. Both arguments are strictly boolean and default to false.

  • include_dead = false keeps only entities whose is_alive() is true; a controller is alive while its pawn is.
  • enemies_only = true keeps only entities whose is_enemy() is true: the same rule, including mp_teammates_are_enemies. The local player is never an enemy. Without a local controller, nothing qualifies and the table is empty.

pawns lists C_CSPlayerPawn entities only, the players every built-in feature walks; observer pawns are not included.

events.render(function()
    if not engine.is_in_game() then return end

    for _, pawn in ipairs(entitylist.pawns(true)) do
        local position = render.world_to_screen(pawn:origin())
        if position then
            render.text(tostring(pawn.m_iHealth), position, color(255, 255, 255))
        end
    end
end)

Entity field access, methods and lifetime rules are documented under Entities.

On this page