# Events

**Events:**

```lua
Events.Register(name, callback)
```

Registers a callback function under a given name. The engine will invoke it automatically when the corresponding event fires.

**Paint:**

```lua
Events.Register("Paint", function()
    -- called every frame while the overlay is rendering
    -- use this for all ESP and Draw calls
end)
```

The `Paint` event fires every frame during the overlay render pass. This is where all of your `Draw.*` calls should live — lines, boxes, text, circles, etc. Anything drawn outside of this callback will not render correctly.

**Example:**

```lua
Events.Register("Paint", function()
    local players = Cache.FetchPlayers()
    for _, p in ipairs(players) do
        if p.Valid then
            Draw.Rect(p:BoxMin(), p:BoxMax(), Color.new(255, 0, 0, 255), 0, 1)
        end
    end
end)
```

**Rescan:**

```lua
Events.Register("Rescan", function()
    -- called whenever the player cache is rescanned
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yerba-1.gitbook.io/yerba-docs/api/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
