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

# Exports & events

Public API of Cuxial Electrician: server exports and the hook that runs when a job is paid.

Read whether a player is in an electrician crew, read their level, and run your own code when a job is paid. Everything here runs on the server; the script has no client exports and no public events.

## Server exports

### IsInCrew

Tells whether a player belongs to an electrician crew. A player gets a crew as soon as they open the panel at the NPC, so `true` does not mean that a job is running.

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

| Parameter | Type   | Description              |
| --------- | ------ | ------------------------ |
| `source`  | number | Server id of the player. |

**Returns:** `boolean`.

```lua
if exports.cuxial_electrician:IsInCrew(source) then
    -- the player is in the electrician lobby or working
end
```

### GetProfile

Returns the electrician level and XP of a character, online or offline.

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

| Parameter    | Type   | Description                                                                                              |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------- |
| `identifier` | string | Character identifier used by your framework (the `citizenid` in QBox and QBCore, the identifier in ESX). |

**Returns:** `{ level: number, xp: number }`, or `nil` when the character has never opened the job or the database is not ready.

```lua
local profile = exports.cuxial_electrician:GetProfile(citizenid)
if profile and profile.level >= 10 then
    -- unlock something for experienced electricians
end
```

`xp` is the progress inside the current level, not the total earned.

## Hook: onFinish

`server/hooks.lua` is an open file with one function that the script calls once per paid member, right after the money and the XP have been given. Write your own code inside it: extra rewards, statistics, integration with another resource.

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

| Parameter     | Type   | Description                                                              |
| ------------- | ------ | ------------------------------------------------------------------------ |
| `src`         | number | Server id of the member.                                                 |
| `data.runId`  | number | Number of the job in `cuxial_jobs_runs`. `0` when it could not be saved. |
| `data.region` | number | `id` of the region in `data/regions.lua`.                                |
| `data.score`  | number | Repairs made by this member that count towards the job.                  |
| `data.money`  | number | Money this member received.                                              |
| `data.xp`     | number | XP this member received.                                                 |
| `data.owner`  | string | Character identifier of the crew owner.                                  |

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

```lua
function CuxialElectrician.hooks.onFinish(src, data)
    print(('Player %d finished region %d: %d repairs, $%d, %d XP'):format(
        src, data.region, data.score, data.money, data.xp))
end
```

{% endcode %}

{% hint style="info" %}
The hook is not called for members who are disconnected when the trucks are delivered. An error inside the hook is printed to the server console and does not stop the payment.
{% endhint %}

{% hint style="warning" %}
`server/hooks.lua` is replaced when you update the script. Keep a copy of your changes.
{% 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/jobs/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.
