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

# Exports y eventos

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

Consulta si un jugador está en una tripulación de electricistas, lee su nivel y ejecuta tu propio código cuando se paga un trabajo. Todo lo de esta página corre en el servidor; el script no tiene exports de cliente ni eventos públicos.

## Exports de servidor

### IsInCrew

Indica si un jugador pertenece a una tripulación de electricistas. El jugador tiene tripulación desde que abre el panel en el NPC, así que `true` no significa que haya un trabajo en curso.

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

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

**Devuelve:** `boolean`.

```lua
if exports.cuxial_electrician:IsInCrew(source) then
    -- el jugador está en el lobby de electricista o trabajando
end
```

### GetProfile

Devuelve el nivel y la XP de electricista de un personaje, conectado o no.

```lua
local profile = exports.cuxial_electrician:GetProfile(identifier)
```

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

**Devuelve:** `{ level: number, xp: number }`, o `nil` si el personaje nunca ha abierto el trabajo o la base de datos no está lista.

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

`xp` es el progreso dentro del nivel actual, no el total acumulado.

## Gancho: onFinish

`server/hooks.lua` es un archivo abierto con una función que el script llama una vez por cada miembro que cobra, justo después de dar el dinero y la XP. Escribe dentro tu propio código: recompensas extra, estadísticas, integración con otro recurso.

```lua
function CuxialElectrician.hooks.onFinish(src, data)
end
```

| Parámetro     | Tipo   | Descripción                                                          |
| ------------- | ------ | -------------------------------------------------------------------- |
| `src`         | number | Id de servidor del miembro.                                          |
| `data.runId`  | number | Número 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 | Reparaciones de este miembro que cuentan para el trabajo.            |
| `data.money`  | number | Dinero que recibió este miembro.                                     |
| `data.xp`     | number | XP que recibió este miembro.                                         |
| `data.owner`  | string | Identificador de personaje del dueño de la tripulación.              |

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

```lua
function CuxialElectrician.hooks.onFinish(src, data)
    print(('El jugador %d terminó la región %d: %d reparaciones, $%d, %d XP'):format(
        src, data.region, data.score, data.money, data.xp))
end
```

{% endcode %}

{% hint style="info" %}
El gancho no se llama para los miembros desconectados en el momento de entregar los camiones. Un error dentro del gancho se imprime en la consola del servidor y no detiene el pago.
{% endhint %}

{% hint style="warning" %}
`server/hooks.lua` se sustituye al actualizar el script. Guarda una copia de tus cambios.
{% endhint %}


---

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