> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: Finding Fields
icon: search
sidebar_position: 3
---

# Finding Fields

Use this page when you know what object you have in Lua, but you do not know the
field name to read.

## 1. Print the class

Start from the object you already have and print its class or designer name.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:0:071c61ef2ba3"
local pawn = entity.GetLocalPawn()

if pawn and pawn:IsValid() then
    print(pawn:GetClassName())
    print(pawn:GetDesignerName())
end
```

Open the matching Schema page under `client`, for example
[C\_CSPlayerPawn](/cs2/dumped_data/schema/client/C_CSPlayerPawn).

## 2. Search the Schema page

On a Schema page, look for:

* **Field name**: the exact Lua field to read, such as `m_iHealth`;
* **Type**: what kind of value Lua will return;
* **Offset**: useful for FFI or debugging, but not needed for normal field access;
* **Declaring class**: where the field comes from in the inheritance chain.

If a field is inherited from a base class, you still read it from the concrete
entity:

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:1:6ec6caf048c3"
local pawn = entity.GetLocalPlayerPawn()

if pawn and pawn:IsValid() then
    print(pawn.m_iHealth)
end
```

## 3. Check the field type from Lua

The [`schema`](/cs2/api_reference/engine/schema) namespace lets your script ask
the same questions dynamically.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:2:fbcf5b48124a"
local pawn_type = schema.client["C_CSPlayerPawn"]

if pawn_type then
    local armor_type = pawn_type:GetFieldType("m_ArmorValue")
    if armor_type then
        print(pawn_type:GetFieldOffset("m_ArmorValue"))
        print(armor_type:GetName())
    end
end
```

`GetFieldType` and `GetFieldOffset` can return `nil` for missing fields.
To list only fields declared directly on that class, pass `true` to `:GetFields`:

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:3:89e09f16410c"
local pawn_type = schema.client["C_CSPlayerPawn"]

if pawn_type then
    for _, field in ipairs(pawn_type:GetFields(true) or {}) do
        print(field)
    end
end
```

## 4. Prefer a helper when one exists

Before using a raw field, check the API Reference page for a helper method.

<Columns cols={2}>
  <Column>
    **Helper**

    ```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:4:b65ca1a03fe3"
    local pawn = entity.GetLocalPlayerPawn()
    if pawn and pawn:IsValid() then
        print(pawn:GetHealth())
    end
    ```
  </Column>

  <Column>
    **Raw field**

    ```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:5:b3a830ff841e"
    local pawn = entity.GetLocalPlayerPawn()
    if pawn and pawn:IsValid() then
        print(pawn.m_iHealth)
    end
    ```
  </Column>
</Columns>

Both can read the same live object. The helper is clearer; the raw field reaches
data that has no helper yet.

## 5. Follow nested values

Fields may return nested schema objects, arrays, vectors, handles, or other
entity wrappers. Follow the type link in the Schema page when you are unsure.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:6:b1a243456eeb"
local pawn = entity.GetLocalPlayerPawn()
local weapon = pawn and pawn:IsValid() and pawn:GetActiveWeapon()

if weapon and weapon:IsValid() then
    print(weapon.m_iClip1)

    local vdata = weapon:GetWeaponData()
    if vdata then
        print(vdata.m_iMaxClip1)
    end
end
```

[`value.AtomicCollection` and `value.FixedArray`](/cs2/api_reference/engine/value)
expose `:Value()` to copy container membership into a one-based Lua table.
Direct access to these live containers uses zero-based indices.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/finding-fields:7:d8d3dcd586d0"
local pawn = entity.GetLocalPlayerPawn()

if pawn and pawn:IsValid() then
    local weapons = pawn:GetMyWeapons()
    if weapons then
        for _, weapon in ipairs(weapons:Value()) do
            if weapon and weapon:IsValid() then
                print(weapon:GetClassName())
            end
        end
    end
end
```

<Warning>
  Do not hardcode offsets for normal entity reads. Use field names. Re-check Schema after CS2 updates because field names, types, and offsets follow the current game build.
</Warning>
