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

---
title: Schema System
icon: list-tree
sidebar_position: 4
---

# Schema System

The Schema pages show Source 2's reflected classes and enums. In Lua, the
[`schema`](/cs2/api_reference/engine/schema) namespace lets scripts inspect that
same kind of information without copying offsets by hand.

## Look up a class

`schema` is grouped by scope. For CS2 gameplay entities, the scope you use most
often is `client`.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/schema-system:0:76210ef3aabf"
local pawn_type = schema.client["C_CSPlayerPawn"]

if pawn_type then
    print(pawn_type:GetName())
    print(pawn_type:GetSize())

    for _, base in ipairs({pawn_type:GetBaseClasses()}) do
        print(base.type:GetName(), " at offset ", base.offset)
    end
end
```

`GetBaseClasses()` returns one `{type, offset}` table per direct base class as
multiple return values. Collect them with `{...}` before iterating.

Use bracket lookup for class names. It works well with names you discover at
runtime:

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/schema-system:1:80bfaa053b65"
local pawn = entity.GetLocalPawn()

if pawn and pawn:IsValid() then
    local class_type = schema.client[pawn:GetClassName()]
    if class_type then
        print(class_type:GetName())
    end
end
```

## Inspect fields

Use `:GetFields`, `:GetFieldOffset`, and `:GetFieldType` to answer the questions
you would normally open a Schema page for.

<Tabs items={["list fields", "offset", "field type"]}>
  <Tab title="list fields">
    ```lua luaintelligence="true" semantic="lua:cs2:cs2/dumped_data/overview/schema-system:2:5fda6b6a94c3"
    local t = schema.client["C_BaseEntity"]

    if t then
        for _, field in ipairs(t:GetFields() or {}) do
            print(field)
        end
    end
    ```
  </Tab>

  <Tab title="offset">
    ```lua luaintelligence="true" semantic="lua:cs2:cs2/dumped_data/overview/schema-system:3:e8ca0acea2e8"
    local t = schema.client["C_BaseEntity"]

    if t then
        print(t:GetFieldOffset("m_iHealth"))
    end
    ```
  </Tab>

  <Tab title="field type">
    ```lua luaintelligence="true" semantic="lua:cs2:cs2/dumped_data/overview/schema-system:4:cf042ef003a9"
    local t = schema.client["C_CSPlayerPawn"]

    local field_type = t and t:GetFieldType("m_ArmorValue")
    if field_type then
        print(field_type:GetName())
    end
    ```
  </Tab>
</Tabs>

`t:GetFields()` includes inherited fields. `t:GetFields(true)` lists fields
declared directly on `t`. These operations require a declared class type;
`GetFields` can return `nil`, and missing fields have no offset or field type.

## Read enum tables

Some Source 2 enum tables can be read directly from `schema` by enum name.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/schema-system:5:dce8ae0d2da4"
local buttons = schema.EInButtonState

if buttons then
    print(buttons.IN_BUTTON_UP)
    print(buttons.IN_BUTTON_DOWN)
end
```

Use this when an API field stores an engine enum value and you want named
constants instead of magic numbers.

## Metadata

`schema.Type:GetMetadata()` returns metadata attached to a type. Passing a field name
returns metadata for that field.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/schema-system:6:19c16f28425a"
local pawn_type = schema.client["C_CSPlayerPawn"]

if pawn_type then
    for name in pairs(pawn_type:GetMetadata()) do
        print("Class metadata: ", name)
    end
    for name in pairs(pawn_type:GetMetadata("m_ArmorValue")) do
        print("Field metadata: ", name)
    end
end
```

Metadata values are borrowed native pointers. The example lists their keys
without dereferencing those pointers. Most gameplay scripts only need fields,
field types, and enums.

## Containers and wrapper values

`schema.Type` describes a type. Values read from game memory use the separate
[`value.*` wrappers](/cs2/api_reference/engine/value), such as
`value.AtomicCollection`, `value.FixedArray`, and `value.DeclaredClass`.
These wrappers view live memory; they do not allocate new game objects.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/schema-system:7:9653bd2cc56f"
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
```

Collections and fixed arrays use zero-based direct indices. `:Value()` returns
a one-based Lua table snapshot; any entities in the table remain live objects.
Recheck them before later use.

Quantized floats use `:Get()` to read an ordinary number. A quantized field's
components may themselves be wrappers, so check the returned type instead of
assuming every value exposes `:Value()`.

Open a wrapper's API page or hover it in a Lua Intelligence code block to see
its supported methods.

## When to use schema directly

Use `schema` when you need to:

* discover fields dynamically;
* inspect a field's type before reading it;
* read offsets for FFI or debugging;
* list enum values by name;
* build tooling that adapts after game updates.

For normal gameplay scripts, prefer `entity` helpers and raw field names from
the Schema pages.

<Note>
  Schema data follows the current CS2 build. If a script starts reading wrong data after an update, verify the field again in Dumped Data before changing Lua logic.
</Note>
