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

# Events

> Register callbacks for built-in engine events.

## Registration

```lua theme={null} theme={null}
local id = events.on(name, callback)
events.off(id)
```

## Built-in events

### paint

```lua theme={null} theme={null}
events.on('paint', function()
    -- render.* functions work here
end)
```

Called every frame. See [Render](https://lua.nlcrack.one/rendering/render.md) for drawing functions.

### createmove

```lua theme={null} theme={null}
events.on('createmove', function(cmd)
    local fw, left = cmd:move()
    cmd:set_move(fw * 0.5, left * 0.5)
end)
```

Called every user command. Receives a [cmd](https://lua.nlcrack.one/runtime/command.md) object.

### frame\_stage

```lua theme={null} theme={null}
events.on('frame_stage', function(s)
    if s == stage.render_start then
        -- run after simulation
    end
end)
```

Game thread. Available stages:

| Constant | Description |
| - | - |
| `stage.lagcomp` | Lag compensation update |
| `stage.net_update_end` | Network update finished |
| `stage.render_start` | End of client frame simulate |

### override\_view

```lua theme={null} theme={null}
events.on('override_view', function(view)
    view:set_fov(110)
end)
```

**View methods:**

| Method | Description |
| - | - |
| `fov()` | Current FOV |
| `set_fov(v)` | Set FOV |
| `viewmodel_fov()` | Viewmodel FOV |
| `set_viewmodel_fov(v)` | Set viewmodel FOV |
| `origin()` | Camera position |
| `set_origin(vec)` | Set camera position |
| `angles()` | Camera angles |
| `set_angles(vec)` | Set camera angles |
| `aspect()` | Aspect ratio |

### input

```lua theme={null} theme={null}
events.on('input', function(message, wparam, lparam)
    if wparam == 0x1B then return true end -- block Escape
end)
```

Return `true` to consume the message.

### menu\_toggled

```lua theme={null} theme={null}
events.on('menu_toggled', function(open) end)
```

### movement\_hit

```lua theme={null} theme={null}
events.on('movement_hit', function(name, speed, fall)
    -- name: 'edge bug', 'jump bug', 'pixel surf', 'texture bug'
end)
```

### level\_init / level\_shutdown

```lua theme={null} theme={null}
events.on('level_init', function(map) end)
events.on('level_shutdown', function() end)
```

### unload

```lua theme={null} theme={null}
events.on('unload', function() end)
```

Called when the script is about to unload.

## Game events

Any name not listed above is forwarded as a game event (`player_hurt`, `round_start`, etc.).

```lua theme={null} theme={null}
events.on('player_hurt', function(e)
    local victim = e:get_pawn('userid')
    local damage = e:get_int('dmg_health')
    print(damage)
end)
```

**Event methods:**

| Method | Returns |
| - | - |
| `name()` | Event name |
| `get_int(key)` | `number` |
| `get_float(key)` | `number` |
| `get_bool(key)` | `bool` |
| `get_string(key)` | `string` |
| `get_controller(key)` | `entity` |
| `get_pawn(key)` | `entity` |

The event object is valid only inside the callback.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.