> For the complete documentation index, see [llms.txt](https://visionstore.gitbook.io/visionstore-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://visionstore.gitbook.io/visionstore-docs/scripts/boxing-creator/developers/events-and-exports.md).

# Events and exports

Listen to fights from any resource, and query or control the script with exports.

## Events

Every hook is also fired as a **local event** named `chapo_boxing:<hook>`, with the same arguments. Any resource can listen, on the server or client side.

```lua
-- server.lua of any resource
AddEventHandler('chapo_boxing:onMatchEnd', function(match, result)
    print(('%s won by %s'):format(result.winner and match[result.winner].name or 'nobody', result.kind))
end)
```

| Server events                                | Client events                                |
| -------------------------------------------- | -------------------------------------------- |
| `chapo_boxing:canJoin` · `onJoin`            | `chapo_boxing:onEnterRing` · `onLeaveRing`   |
| `chapo_boxing:canBet` · `onBet`              | `chapo_boxing:onRoundStart` · `onFightEvent` |
| `chapo_boxing:onMatchStart` · `onRoundStart` | `chapo_boxing:onHitLanded` · `onHitTaken`    |
| `chapo_boxing:onHit` · `onKnockdown`         | `chapo_boxing:onFinish`                      |
| `chapo_boxing:onRoundEnd` · `onMatchEnd`     | `chapo_boxing:canUseGloves` · `onGloves`     |

{% hint style="warning" %}
Use **`AddEventHandler`**. These events are local only. Don't register them with `RegisterNetEvent`, which would let clients fake them. Events can only **listen**: to refuse an action, use the `can...` hooks in `open/sv_hooks.lua`.
{% endhint %}

## Server exports

```lua
local boxing = exports['Chapo_BoxingCreator']
```

| Export                                           | Returns                                                                                                          |
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| `boxing:GetRings()`                              | Every ring `{ id, label, center, join, heading, size, rules, prop }`                                             |
| `boxing:GetRing(ringId)`                         | One ring, or `nil`                                                                                               |
| `boxing:GetMatch(ringId)`                        | The [match table](/visionstore-docs/scripts/boxing-creator/developers.md#the-match-table) on that ring, or `nil` |
| `boxing:GetMatches()`                            | Every running match                                                                                              |
| `boxing:GetPlayerMatch(source)`                  | `match, corner` for a player in a fight or lobby, else `nil, nil`                                                |
| `boxing:IsInFight(source)`                       | `true` from the walk-out to the result                                                                           |
| `boxing:StopMatch(ringId, reason)`               | Ends it as a no contest (refunds everything). `true` if stopped                                                  |
| `boxing:GetStats(identifier)`                    | A record: `{ name, wins, losses, draws, kos, rating, tier, streak, best }`                                       |
| `boxing:GetPlayerStats(source)`                  | The same, for an online player                                                                                   |
| `boxing:GetLeaderboard()`                        | The leaderboard rows                                                                                             |
| `boxing:Notify(source, localeKey, params, kind)` | Show a translated notification                                                                                   |

## Client exports

| Export                | Returns                                             |
| --------------------- | --------------------------------------------------- |
| `IsFighting()`        | `true` while this player is in a fight              |
| `GetFight()`          | `{ ringId, corner, phase, opponent }` or `nil`      |
| `GetSpectatingRing()` | The ring id whose scoreboard is on screen, or `nil` |
| `IsMenuOpen()`        | `true` while the ring menu or creator has focus     |
| `GetRings()`          | The rings this client knows about                   |
| `isWearingGloves()`   | `true` if gloves are on                             |
| `useGloves()`         | Lace up / take off (same as using the item)         |

## Common uses

{% tabs %}
{% tab title="Stop other scripts during fights" %}

```lua
-- In your robbery / tackle / carry script (server)
if exports['Chapo_BoxingCreator']:IsInFight(source) then
    return -- leave boxers alone
end
```

Fighters also carry the state bag `cbxFighting` (the ring id) from the walk-out until they leave the ring:

```lua
if Player(source).state.cbxFighting then return end
```

{% endtab %}

{% tab title="Discord fight log" %}

```lua
local WEBHOOK = 'https://discord.com/api/webhooks/...'

AddEventHandler('chapo_boxing:onMatchEnd', function(match, result)
    if result.kind == 'nocontest' then return end
    local w = result.winner and match[result.winner]
    local text = w and ('🥊 **%s** beat **%s** by %s (round %d) at %s'):format(
        w.name, match[result.winner == 'red' and 'blue' or 'red'].name, result.kind:upper(), result.round, match.label)
        or ('🥊 Draw at %s'):format(match.label)
    PerformHttpRequest(WEBHOOK, function() end, 'POST', json.encode({ content = text }),
        { ['Content-Type'] = 'application/json' })
end)
```

{% endtab %}

{% tab title="Champion role" %}

```lua
-- Give the #1 of the leaderboard a perk every restart
CreateThread(function()
    Wait(5000)
    local top = exports['Chapo_BoxingCreator']:GetLeaderboard()[1]
    if top then print(('Current champion: %s (%d)'):format(top.name, top.rating)) end
end)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://visionstore.gitbook.io/visionstore-docs/scripts/boxing-creator/developers/events-and-exports.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
