entity
The entity namespace provides functions for querying players, weapons, entities, and server resource tables.
Functions
Section titled “Functions”entity.get
Section titled “entity.get”local ent = entity.get(index: number, is_userid?: boolean) --> entity_t | player_t | weapon_t | nilRetrieves an entity object by its entity index.
- If
is_useridistrue,indexis interpreted as an engine userid instead of an entity index. - Returns a strongly typed object:
player_tfor players,weapon_tfor weapons, andentity_tfor general entities. - Returns
nilif the index does not correspond to a valid entity.
entity.from_handle
Section titled “entity.from_handle”local ent = entity.from_handle(handle: number) --> entity_t | player_t | weapon_t | nilResolves 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()) endendentity.get_local_player
Section titled “entity.get_local_player”local me = entity.get_local_player() --> player_t | nilReturns the player_t instance for the local player client, or nil if not in a server or not yet spawned.
entity.get_players
Section titled “entity.get_players”local players = entity.get_players(enemies_only?: boolean) --> table of player_tReturns a 1-based Lua table containing active player objects currently connected to the server.
- Pass
trueto 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 endendentity.get_player_resource
Section titled “entity.get_player_resource”local resource = entity.get_player_resource() --> player_resource_t | nilReturns the CCSPlayerResource entity, exposing team-wide array netprops indexed by entity index (e.g. m_iKills, m_iDeaths, m_iPing, m_iScore, m_iAssists).
Special Entity Capabilities
Section titled “Special Entity Capabilities”Shared Users (player:friendly())
Section titled “Shared Users (player:friendly())”local is_aimsense_user = player:friendly() --> booleanReports 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") endendSteam Avatars (player:get_avatar())
Section titled “Steam Avatars (player:get_avatar())”local avatar_img = player:get_avatar() --> image_t | nilRetrieves 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.
