Orion Solutions Docs
ORION SOLUTIONS LUA API

Entity

Entity access, player and weapon helpers, and dynamic netprops exposed to Lua scripts.

The entity library provides access to client entities, players and weapons. Entity objects expose helper methods and dynamically resolved netprops through the same Lua object.

entity.get

entity.get(index: number[, by_user_id: boolean]): entity | nil

Returns the entity at an entity index. When by_user_id is true, the first argument is treated as a player user ID and converted to an entity index.

Arguments

NameTypeDescription
indexnumberEntity index, or player user ID when by_user_id is enabled.
by_user_idbooleanOptional. Resolve the first argument with GetPlayerForUserID.

Example

local player = entity.get(1)

if player then
    print(player:get_name())
end

entity.get_local_player

entity.get_local_player(): entity | nil

Returns the local player entity, or nil when no valid local player is available.

Example

local local_player = entity.get_local_player()

if local_player then
    print(local_player:get_name())
end

entity.get_players

entity.get_players([enemies_only: boolean[, include_dormant: boolean[, callback: function]]]): table

Gets player entities. Without a callback, the function returns a normal 1-based Lua array. When a callback is supplied, each matching player is passed directly to the callback.

Arguments

NameTypeDescription
enemies_onlybooleanOptional. Include only players on a different team from the local player.
include_dormantbooleanOptional. Include dormant players.
callbackfunctionOptional. Called once for each matching player entity.

Examples

for _, player in ipairs(entity.get_players(true, false)) do
    print(player:get_name())
end

entity.get_players(false, true, function(player)
    print(player:get_index())
end)

entity.get_entities

entity.get_entities([class: number | string[, include_dormant: boolean[, callback: function]]]): table

Gets client entities up to the highest entity index. The optional class filter accepts either a numeric class ID or a network class name.

Arguments

NameTypeDescription
classnumber | stringOptional class ID or network class name filter.
include_dormantbooleanOptional. Include dormant entities.
callbackfunctionOptional. Called once for each matching entity.

Examples

local weapons = entity.get_entities("CWeaponAK47", true)

for _, weapon in ipairs(weapons) do
    print(weapon:get_classname())
end

entity.get_entities(nil, false, function(ent)
    print(ent:get_classid(), ent:get_classname())
end)

Entity Type Checks

MethodDescription
ent:is_player()Returns whether the entity is a player.
ent:is_weapon()Returns whether the entity is a weapon.
ent:is_dormant()Returns whether the entity is dormant.
ent:is_alive()Returns whether the entity is a valid living player.
ent:is_enemy()Returns whether the player is on a different team from the local player.

Basic Entity Information

MethodReturn value
ent:get_index()Entity index, or -1 when invalid.
ent:get_name()Player name, weapon name, or network class name depending on entity type.
ent:get_classname()Network class name.
ent:get_classid()Numeric client class ID, or -1 when invalid.
ent:get_model_name()Engine model name, or an empty string when unavailable.

Position And Simulation Time

MethodReturn value
ent:get_origin()Vector absolute origin.
ent:get_angles()QAngle absolute angles.
ent:get_simulation_time()Table containing current and old simulation times.

Example

local ent = entity.get_local_player()

if ent then
    local origin = ent:get_origin()
    local angles = ent:get_angles()
    local simulation = ent:get_simulation_time()

    print(origin.x, origin.y, origin.z)
    print(angles.pitch, angles.yaw, angles.roll)
    print(simulation.current, simulation.old)
end

Player Helpers

MethodDescription
player:get_player_weapon()Returns the active weapon entity, or nil.
player:get_eye_position()Returns the player shoot position as a Vector.
player:get_bone_position(bone)Returns the requested bone position as a Vector. Invalid bones return 0, 0, 0.
player:get_hitbox_position(hitbox)Returns the center of the requested hitbox as a Vector. Invalid hitboxes return 0, 0, 0.

Example

local player = entity.get_local_player()

if player then
    local eyes = player:get_eye_position()
    local bone = player:get_bone_position(8)
    local hitbox = player:get_hitbox_position(0)

    print(eyes.x, eyes.y, eyes.z)
    print(bone.x, bone.y, bone.z)
    print(hitbox.x, hitbox.y, hitbox.z)
end

Weapon Helpers

MethodReturn value
weapon:get_weapon_index()Weapon item ID, or -1 when invalid.
weapon:get_weapon_owner()Owning entity, or nil.
weapon:get_max_speed()Current maximum player speed for the weapon. Uses alternate speed while zoomed.
weapon:get_spread()Current weapon spread.
weapon:get_inaccuracy()Current weapon inaccuracy.

Example

local player = entity.get_local_player()

if player then
    local weapon = player:get_player_weapon()

    if weapon then
        print(weapon:get_weapon_index())
        print(weapon:get_max_speed())
        print(weapon:get_spread())
        print(weapon:get_inaccuracy())
    end
end

Dynamic Netprops

Unknown string keys on an entity object are resolved as recv-table netprops for that entity class. Netprops can be read directly using normal Lua field syntax.

local player = entity.get_local_player()

if player then
    print(player.m_iHealth)
    print(player.m_iTeamNum)
    print(player.m_flSimulationTime)
end

Writable scalar netprops can also be assigned directly. Invalid names, array assignments or incompatible value types produce a Lua error.

local player = entity.get_local_player()

if player then
    player.m_iHealth = 100
end
Supported Netprop Types

The current Entity implementation handles integer, float, Vector, VectorXY, string and Int64 recv properties. Netprops whose names begin with m_b are treated as booleans.

Netprop Arrays

Array netprops return an array proxy that can be read or written by index.

local player = entity.get_local_player()

if player then
    local pose = player.m_flPoseParameter

    print(pose[0])
    pose[0] = 0.5
end
0-Based Netprop Arrays

Netprop array proxies use C++-style 0-based indexing. This differs from normal Lua arrays, which are usually 1-based.

Vector And QAngle Values

Entity methods and vector netprops can return Orion Solutions support value types.

TypeFields
Vectorx, y, z
QAnglepitch, yaw, roll
local player = entity.get_local_player()

if player then
    local origin = player:get_origin()
    local angles = player:get_angles()

    print(origin.x, origin.y, origin.z)
    print(angles.pitch, angles.yaw, angles.roll)
end
Entity Lifetime

Lua entity objects store an entity index rather than a permanent raw pointer. Methods resolve the current entity from the entity list each time and return safe fallback values when the entity is no longer valid.