Skip to content

entity

The entity namespace provides functions for querying players, weapons, entities, and server resource tables.


local ent = entity.get(index: number, is_userid?: boolean) --> entity_t | player_t | weapon_t | nil

Retrieves an entity object by its entity index.

  • If is_userid is true, index is interpreted as an engine userid instead of an entity index.
  • Returns a strongly typed object: player_t for players, weapon_t for weapons, and entity_t for general entities.
  • Returns nil if the index does not correspond to a valid entity.

local ent = entity.from_handle(handle: number) --> entity_t | player_t | weapon_t | nil

Resolves a 32-bit EHANDLE integer (such as read from netprops like m_hActiveWeapon or m_hMyWeapons) into an entity instance.

local local_player = entity.get_local_player()
if local_player then
local active_weapon = entity.from_handle(local_player.m_hActiveWeapon)
if active_weapon then
print("Holding: " .. active_weapon:get_classname())
end
end

local me = entity.get_local_player() --> player_t | nil

Returns the player_t instance for the local player client, or nil if not in a server or not yet spawned.


local players = entity.get_players(enemies_only?: boolean) --> table of player_t

Returns a 1-based Lua table containing active player objects currently connected to the server.

  • Pass true to filter and return only enemy players.
  • Does not include dormant or disconnected slots.
local enemies = entity.get_players(true)
for i = 1, #enemies do
local enemy = enemies[i]
if enemy:is_alive() and not enemy:is_dormant() then
-- Process enemy
end
end

local resource = entity.get_player_resource() --> player_resource_t | nil

Returns the CCSPlayerResource entity, exposing team-wide array netprops indexed by entity index (e.g. m_iKills, m_iDeaths, m_iPing, m_iScore, m_iAssists).


local is_aimsense_user = player:friendly() --> boolean

Reports whether another player is also running Aimsense. All users broadcast an authenticated heartbeat via voice data roughly once per second.

for _, player in ipairs(entity.get_players()) do
if player:friendly() then
print(player:get_name() .. " is using Aimsense")
end
end

local avatar_img = player:get_avatar() --> image_t | nil

Retrieves the player’s Steam avatar texture ready for render.texture.


Custom Scoreboard Icons (player:set_icon())

Section titled “Custom Scoreboard Icons (player:set_icon())”
player:set_icon(icon: string | number | nil)

Sets a custom icon in the rank badge slot on CS:GO’s scoreboard for that player:

  • SVG String: Pass an SVG string (e.g. '<svg viewBox="0 0 24 24">...</svg>').
  • Image Path: Pass an image URI reachable by Panorama (e.g. "file://{images}/icons/aimsense/logo.svg").
  • nil: Clears any custom icon and restores standard rank/level display.
  • Number: Overrides the Steam profile level badge number.