> For the complete documentation index, see [llms.txt](https://docs.cuxial.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cuxial.com/scripts/es/ocio/cuxial-pvp/developers.md).

# Exports y eventos

API pública de Cuxial PvP: exports para abrir el menú y estado para saber quién está en partida.

Abre el menú desde tus propios recursos y averigua si un jugador está combatiendo o mirando una partida. Cuxial PvP tiene dos exports de cliente y dos valores de estado del jugador; no expone exports de servidor.

## Exports de cliente

### toggleUI

Abre o cierra el menú. La llamada se ignora mientras el jugador está en una partida.

```lua
exports.CuxiaPvP:toggleUI(toggle)
```

| Parámetro | Tipo    | Descripción                             |
| --------- | ------- | --------------------------------------- |
| `toggle`  | boolean | `true` abre el menú, `false` lo cierra. |

**Devuelve:** nada.

```lua
-- Abre el menú con tu propio comando
RegisterCommand('arena', function()
    exports.CuxiaPvP:toggleUI(true)
end, false)
```

### isPlaying

Indica si el jugador local está en una partida.

```lua
local playing = exports.CuxiaPvP:isPlaying()
```

**Devuelve:** `boolean`. `true` desde que carga la partida hasta que termina.

```lua
-- Omite tu propia pantalla de muerte durante una partida
if exports.CuxiaPvP:isPlaying() then return end
```

## Estado del jugador

Los dos valores están replicados, así que se pueden leer en el cliente y en el servidor. Trátalos como de solo lectura.

| Estado            | Tipo          | Valor                                                                        |
| ----------------- | ------------- | ---------------------------------------------------------------------------- |
| `inDuel`          | number \| nil | Id de la partida en la que combate el jugador. `nil` fuera de una partida.   |
| `spectatingMatch` | number \| nil | Id de la partida que el jugador está mirando. `nil` cuando no es espectador. |

El id de una partida es también el routing bucket en el que corre.

{% tabs %}
{% tab title="Cliente" %}

```lua
if LocalPlayer.state.inDuel then
    -- el jugador local está en una partida
end
```

{% endtab %}

{% tab title="Servidor" %}

```lua
local state = Player(source).state

if state.inDuel or state.spectatingMatch then
    -- el jugador está dentro de la instancia de una partida
end
```

{% endtab %}
{% endtabs %}

Para reaccionar cuando un jugador entra o sale de una partida:

```lua
AddStateBagChangeHandler('inDuel', nil, function(bagName, _, value)
    local player = GetPlayerFromStateBagName(bagName)
    if player == 0 then return end

    if value then
        -- entró en la partida con id `value`
    else
        -- salió de la partida
    end
end)
```

## Eventos que Cuxial PvP lanza a otros scripts

Son eventos de cliente enviados a los scripts elegidos en `data/config.lua`.

| Evento                         | Cuándo                                                                            | Se define en    |
| ------------------------------ | --------------------------------------------------------------------------------- | --------------- |
| Cada evento de `revive.events` | Tras cada ronda de duelo, en cada reaparición de Gun Game y al acabar una partida | `revive`        |
| `av_weather:freeze`            | Al empezar y al acabar una partida, con `weatherSystem = 'av'`                    | `weatherSystem` |
| `cd_easytime:PauseSync`        | Al empezar y al acabar una partida, con `weatherSystem = 'cd'`                    | `weatherSystem` |

Los eventos de revivir se lanzan sin argumentos. Para conectar un script que necesite otra cosa, añade tu propio evento a `revive.events` y gestiónalo:

```lua
AddEventHandler('myserver:pvpRevive', function()
    -- revive al jugador local con tu propio script de ambulancia
end)
```


---

# 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://docs.cuxial.com/scripts/es/ocio/cuxial-pvp/developers.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.
