> 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/trabajos/cuxial-diving/developers.md).

# Exports y eventos

API pública de Cuxial Diving: exports, el gancho de fin de trabajo y el estado del ancla del barco.

Lee el nivel de un buzo, comprueba si un jugador está en una tripulación y ejecuta tu propio código cuando se paga un trabajo. Cuxial Diving no expone eventos públicos.

## Exports de servidor

### IsInCrew

Dice si un jugador está en una tripulación de buceo. Un jugador tiene tripulación desde el momento en que abre el panel del trabajo.

```lua
local inCrew = exports.cuxial_diving:IsInCrew(source)
```

| Parámetro | Tipo   | Descripción                 |
| --------- | ------ | --------------------------- |
| `source`  | number | Id de servidor del jugador. |

**Devuelve:** `boolean`.

```lua
if exports.cuxial_diving:IsInCrew(source) then
    -- el jugador está ocupado con el trabajo de buceo
end
```

### GetProfile

Devuelve el nivel y la experiencia de buceo de un personaje. Funciona también con el personaje desconectado.

```lua
local profile = exports.cuxial_diving:GetProfile(citizenid)
```

| Parámetro   | Tipo   | Descripción                                               |
| ----------- | ------ | --------------------------------------------------------- |
| `citizenid` | string | Identificador del personaje, tal como lo da tu framework. |

**Devuelve:** `{ level: number, xp: number }`, o `nil` cuando el personaje no tiene perfil de buceo o la base de datos no está lista.

```lua
local profile = exports.cuxial_diving:GetProfile(citizenid)
if profile and profile.level >= 10 then
    -- desbloquea algo para buzos con experiencia
end
```

## Gancho de fin de trabajo

`server/hooks.lua` está abierto para editar. Su función `CuxialDiving.hooks.onFinish` se ejecuta en el servidor una vez por cada miembro conectado, justo después de pagarle un trabajo entregado.

{% code title="server/hooks.lua" %}

```lua
function CuxialDiving.hooks.onFinish(src, data)
    if data.region == 4 then
        exports.my_resource:AddReputation(src, 5)
    end
end
```

{% endcode %}

| Parámetro     | Tipo   | Descripción                                                    |
| ------------- | ------ | -------------------------------------------------------------- |
| `src`         | number | Id de servidor del jugador.                                    |
| `data.runId`  | number | Id del trabajo en el historial. `0` cuando no se pudo guardar. |
| `data.region` | number | `id` de la región, de `data/regions.lua`.                      |
| `data.score`  | number | Piezas obligatorias recogidas por este jugador.                |
| `data.money`  | number | Dinero pagado a este jugador.                                  |
| `data.xp`     | number | Experiencia dada a este jugador.                               |
| `data.owner`  | string | Identificador del personaje del dueño de la tripulación.       |

{% hint style="info" %}
El gancho no se ejecuta en los trabajos reiniciados o cancelados, ni para los miembros desconectados en la entrega. Un error dentro de él se imprime en la consola y no detiene el pago.
{% endhint %}

## Estado del barco

El barco de trabajo lleva dos state bags replicados que otros recursos pueden leer.

| State bag      | Tipo    | Descripción                                                                                                  |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `divingAnchor` | boolean | `true` mientras el ancla está echada. Solo lectura: el servidor restaura su valor si otro recurso lo cambia. |
| `fuel`         | number  | Nivel de combustible puesto al aparecer el barco, de `boat.fuel`.                                            |

```lua
local anchored = Entity(vehicle).state.divingAnchor == true
```

## Motivos de los pagos

Los pagos pasan por tu framework con estos motivos, que puedes usar para filtrar tus propios registros de dinero.

| Motivo                 | Cuándo                                            |
| ---------------------- | ------------------------------------------------- |
| `cuxial-diving`        | Pago de un trabajo entregado.                     |
| `cuxial-diving-daily`  | Recompensa de una tarea diaria.                   |
| `cuxial-diving-market` | Compra o venta en el mercado.                     |
| `cuxial-diving-refund` | Devolución de una compra que no se pudo entregar. |


---

# 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/trabajos/cuxial-diving/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.
