> 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-gardener/developers.md).

# Exports y eventos

API pública de Cuxial Gardener: exports de servidor y el gancho que se ejecuta al pagar un trabajo.

Comprueba si un jugador está trabajando de jardinero, lee su nivel y ejecuta tu propio código cuando se paga un trabajo. Todo lo de esta página es de servidor. Cuxial Gardener no tiene exports de cliente ni eventos públicos.

## Exports de servidor

### IsInCrew

Indica si un jugador está en una tripulación de jardineros. La tripulación existe desde que el jugador abre el panel del trabajo, así que no significa que haya un trabajo en curso.

```lua
exports.cuxial_gardener:IsInCrew(source)
```

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

**Devuelve:** `boolean`.

```lua
if exports.cuxial_gardener:IsInCrew(source) then
    -- el jugador está en el trabajo de jardinero
end
```

### GetProfile

Devuelve el nivel y la XP de jardinero de un personaje. Funciona también con personajes desconectados.

```lua
exports.cuxial_gardener:GetProfile(identifier)
```

| Parámetro    | Tipo   | Descripción                                                                 |
| ------------ | ------ | --------------------------------------------------------------------------- |
| `identifier` | string | Identificador de personaje de tu framework (el citizenid en QBox y QBCore). |

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

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

## Gancho: onFinish

`server/hooks.lua` es un archivo abierto. Su función `onFinish` se ejecuta una vez por cada miembro conectado de la tripulación cuando se paga un trabajo. Escribe tu código dentro: sumar reputación, dar un premio extra, enviar tu propio registro.

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

```lua
function CuxialGardener.hooks.onFinish(src, data)
    -- tu código
end
```

{% endcode %}

| Parámetro     | Tipo   | Descripción                                                      |
| ------------- | ------ | ---------------------------------------------------------------- |
| `src`         | number | Id de servidor del jugador que ha cobrado.                       |
| `data.runId`  | number | Id del trabajo en `cuxial_jobs_runs`. `0` si no se pudo guardar. |
| `data.region` | number | `id` de la región en `data/regions.lua`.                         |
| `data.score`  | number | Tareas hechas por este jugador (césped, poda, ramas, flores).    |
| `data.bonus`  | number | Tareas extra hechas por este jugador (regar, guardar ramas).     |
| `data.money`  | number | Dinero pagado a este jugador.                                    |
| `data.xp`     | number | XP dada a este jugador.                                          |
| `data.owner`  | string | Identificador de personaje del dueño de la tripulación.          |

```lua
function CuxialGardener.hooks.onFinish(src, data)
    if data.region == 5 and data.score >= 20 then
        exports.ox_inventory:AddItem(src, 'water', 1)
    end
end
```

{% hint style="info" %}
Un error dentro del gancho se captura y se muestra en la consola del servidor. El pago no se ve afectado.
{% endhint %}

## Base de datos

Las consultas de solo lectura sobre estas tablas son seguras. Las filas de este trabajo tienen `job = 'gardener'`.

| Tabla                     | Contenido                                                                                                    |
| ------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `cuxial_jobs_players`     | Una fila por personaje: `level`, `xp`, progreso diario.                                                      |
| `cuxial_jobs_runs`        | Trabajos terminados: `region`, `owner`, `crew_size`, `outcome` (`done`, `reset`, `abandoned`), inicio y fin. |
| `cuxial_jobs_run_members` | Lo que hizo y ganó cada miembro en un trabajo: `score`, `bonus`, `money`, `xp`.                              |
| `cuxial_jobs_audit`       | Filas de auditoría: trabajo terminado, trabajo reiniciado, acciones de staff.                                |


---

# 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-gardener/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.
