entities
Access players and controllers in the entity list.
Do note that you should call :valid() after a map change.
Lookup
entities.get(index: number): entity | nil
- Returns the entity at the given index.
entities.max_index(): number
- Returns the highest entity index.
entities.for_each_player(callback: (ent: entity) => void)
- Iterates every player pawn.
entities.for_each_controller(callback: (ent: entity) => void)
- Iterates every player controller.
entities.for_each(callback: (ent: entity) => void)
- Iterates every valid entity index.
entities.for_each_class(class_name: string, callback: (ent: entity) => void)
- Iterates entities whose schema class name matches exactly (e.g.
C_SmokeGrenadeProjectile).
entities.for_each_weapon(callback: (ent: entity) => void)
- Iterates world weapon entities.
entities.for_each_projectile(callback: (ent: entity) => void)
- Iterates grenade / projectile entities.
secret.entities.for_each_player(function(ent)
if not ent:valid() or not ent:alive() then return end
if ent:is_enemy() then
print(ent:name(), ent:health())
end
end)
Entity
Methods on entity userdata. Pawn and controller resolve through each other where needed (:pawn(), :controller(), :name(), etc).
entity:valid(): boolean
- Returns if the entity is still valid.
entity:handle(): number
- Returns the entity handle.
entity:index(): number
- Returns the entity index used by
entities.get.
entity:origin(): number, number, number
- Returns origin as
x, y, z.
entity:eye_pos(): number, number, number
- Returns eye position as
x, y, z.
entity:velocity(): number, number, number
- Returns velocity as
x, y, z.
entity:is_player(): boolean
entity:is_controller(): boolean
entity:is_weapon(): boolean
entity:is_projectile(): boolean
entity:is_bomb(): boolean
- Type checks for common entity kinds.
entity:health(): number | nil
- Returns health.
entity:armor(): number | nil
- Returns armor.
entity:has_helmet(): boolean | nil
- Returns if the player has a helmet.
entity:team(): number | nil
- Returns the team number.
entity:alive(): boolean
- Returns if the player is alive.
entity:name(): string | nil
- Returns the player name.
entity:is_enemy(): boolean
- Returns if the player is an enemy.
entity:is_teammate(): boolean
- Returns if the player is a teammate.
entity:is_local(): boolean
- Returns if this is the local player.
entity:steam_id64(): string | nil
- Returns the SteamID64.
entity:pawn(): entity | nil
- Returns the linked pawn from a controller.
entity:controller(): entity | nil
- Returns the linked controller from a pawn.
entity:flags(): number | nil
- Returns entity flags.
entity:dormant(): boolean
- Returns if the entity is dormant.
entity:money(): number | nil
- Returns account money.
entity:weapon(): entity | nil
- Returns the active weapon entity.
entity:weapon_name(): string | nil
- Returns the active weapon name.
entity:clip(): number | nil
- Returns ammo in the clip.
entity:scoped(): boolean | nil
- Returns if the player is scoped.
entity:flash_duration(): number | nil
- Returns flashbang duration.
entity:class_name(): string | nil
- Returns the schema class name.
entity:weapons(): table
- Returns a 1-based list of weapon entities from weapon services.
entity:observer_target(): entity | nil
- Returns the current observer target.
entity:observer_mode(): number | nil
- Returns the observer mode.
entity:hitbox_center(index: number): number, number, number
- Returns hitbox / bone center as
x, y, z.
entity:bone_pos(index: number): number, number, number
- Returns bone position as
x, y, z.
entity:bone_count(): number
- Returns the bone count.
entity:eye_angles(): number, number, number
- Returns eye angles as
pitch, yaw, roll.
entity:aim_punch(): number, number, number
- Returns aim punch as
pitch, yaw, roll.
entity:visible(): boolean
- Returns if the player is visible to the local player (eye-to-eye trace).
entity:can_shoot(tick?: number): boolean
- Returns if the pawn can fire its active weapon. Optional
tickdefaults to the controller tickbase.
entity:inaccuracy(): number | nil
- Returns weapon inaccuracy. Works on a pawn (active weapon) or a weapon entity.
entity:spread(): number | nil
- Returns weapon spread. Works on a pawn or weapon entity.
entity:weapon_type(): number | nil
- Returns
EWeaponType(knife, pistol, rifle, …).
entity:def_index(): number | nil
- Returns the item definition index.
entity:max_speed(): number | nil
- Returns weapon max speed, or pawn max speed if not a weapon.
Schema
Read / write schema fields by name.
entity:get(field: string, ...): any | nil
- Returns a schema field value, or
nilif missing / unsupported. - Prefer
"ClassName->field"(e.g."C_BaseEntity->m_iHealth"). Bare names only resolve when the field is declared on the entity's own class. - Extra string args follow pointer fields (e.g.
ent:get("C_BaseEntity->m_pCollision", "m_vecMins")). - Vectors / angles return
{ x, y, z }. Colors return{ r, g, b, a }. Pointers / handles return numbers.
entity:set(field: string, ..., value: any): boolean
- Sets a schema field. Last argument is the value. Returns
trueon success. - Same naming rules as
get. Use"ClassName->field"for inherited fields. - Vector values accept
{ x, y, z }or{ 1, 2, 3 }.
local me = secret.game.local_player()
if me and me:valid() then
print(me:get("C_BaseEntity->m_iHealth"))
me:set("C_BaseEntity->m_iHealth", 50)
PrintTable(me:get("C_BaseEntity->m_pCollision", "m_vecMins"))
end
local me = secret.game.local_player()
if me and me:valid() then
print(me:name(), me:money(), me:weapon_name())
end