> ## Documentation Index
> Fetch the complete documentation index at: https://lua.starline.one/llms.txt
> Use this file to discover all available pages before exploring further.

# ConVar

> Read, override, restore, and inspect CS2 console variables.

Read and write game console variables.

```lua theme={"dark"}
local gravity = cvar.Find("sv_gravity")
print(gravity:Get()) -- 800
cvar.mp_teammates_are_enemies:Set(true)
```

Overrides are restored when the script unloads, reloads, or is disabled.

[Full convar list](https://cs2.poggu.me/dumped-data/convar-list/) - names, types, defaults and flags.

## Find

```lua theme={"dark"}
local cv = cvar.Find("viewmodel_fov")
```

Returns a ConVar, or `nil` if the name isn't registered. Case-insensitive.

`cvar.viewmodel_fov` does the same thing. `Find`, `RestoreAll` and the flag constants are real members of the table, so a convar sharing one of those names needs `cvar.Find`.

Lookups are cached and case-insensitive. Store frequently used convars in locals:

```lua theme={"dark"}
local sens, yaw = cvar.sensitivity, cvar.m_yaw

-- degrees the view turns per unit of mouse movement
local function DegreesPerCount()
    return sens:Get() * yaw:Get()
end
```

## Get

```lua theme={"dark"}
local value = cv:Get()
```

Returns the value in the convar's own type.

| `cv.type`                                                              | Lua                                |
| ---------------------------------------------------------------------- | ---------------------------------- |
| `bool`                                                                 | boolean                            |
| `int16` `uint16` `int32` `uint32` `int64` `uint64` `float32` `float64` | number                             |
| `string`                                                               | string                             |
| `color`                                                                | `Color`                            |
| `vector3` `vectorws`                                                   | `Vector`                           |
| `qangle`                                                               | `QAngle`                           |
| `vector2`                                                              | table, `{ x = , y = }`             |
| `vector4`                                                              | table, `{ x = , y = , z = , w = }` |

`vector2` and `vector4` have no userdata type of their own, so they read back as plain keyed tables and are written the same way.

## Set

```lua theme={"dark"}
cv:Set(value)
```

Takes the type returned by `Get`, with basic conversions:

```lua theme={"dark"}
cvar.cl_ragdoll_limit:Set(-1)
cvar.bot_loadout:Set("awp")
cvar.r_drawblankworld:Set(true)

cvar.r_drawblankworld:Set(1)     -- number on a bool convar -> true (0 is false)
cvar.cl_ragdoll_limit:Set("12")  -- numeric string -> 12
cvar.cl_ragdoll_limit:Set(true)  -- boolean on a numeric convar -> 1
cvar.bot_loadout:Set(64)         -- number on a string convar -> "64"
```

Invalid conversions and failed overrides error. `Vector` and `QAngle` also accept plain tables. `Color` accepts a `Color` or packed `0xRRGGBBAA` integer. Values are not clamped to `cv.min` or `cv.max`.

Two scripts can hold the same convar. The last one to `Set` it owns the restore, so unloading it puts the engine value back even if another script wrote it first.

## Restore

```lua theme={"dark"}
cv:Restore()
cvar.RestoreAll()
```

Restores the original value. `RestoreAll` restores every convar owned by the current script. Script unload and disable do this automatically.

`Restore` errors if another script owns the override, and does nothing if nobody does.

## Properties

```lua theme={"dark"}
print(cv.name, cv.type, cv.help, cv.default)
```

| Field         |                                                             |
| ------------- | ----------------------------------------------------------- |
| `name`        | string                                                      |
| `type`        | string, from the table above                                |
| `default`     | registered default, or `nil`                                |
| `min` / `max` | registered bounds, or `nil` (most have none)                |
| `help`        | description, or `nil`                                       |
| `flags`       | number, raw `FCVAR_` bits                                   |
| `overridden`  | true while your value is in place                           |
| `original`    | value from before your override, or `nil` if not overridden |

Read-only. Assigning to one errors; use `:Set`.

## Flags

```lua theme={"dark"}
if cv:HasFlag(cvar.FCVAR_CHEAT) then ... end
```

`FCVAR_CHEAT`, `FCVAR_REPLICATED`, `FCVAR_DEVELOPMENTONLY`, `FCVAR_REFERENCE`, `FCVAR_HIDDEN`, `FCVAR_PROTECTED`, `FCVAR_ARCHIVE`, `FCVAR_NOTIFY`, `FCVAR_USERINFO`, `FCVAR_PER_USER`. For anything else test `cv.flags` against a literal.

Use `HasFlag` for flags above bit 31 because LuaJIT's `bit` library is 32-bit.

## Limits

Writes do not fire change callbacks. Server convars work only when `server.dll` is running locally.

<Info>
  For commands with no value behind them, use [`engine.ExecuteCommand`](/engine#executecommand).
</Info>
