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

# Exports & events

Public API of Cuxial Diving: exports, the finish hook and the anchor state of the boat.

Read a diver's level, check whether a player is in a crew and run your own code when a job is paid. Cuxial Diving exposes no public events.

## Server exports

### IsInCrew

Tells whether a player is in a diving crew. A player has a crew from the moment they open the job panel.

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

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

**Returns:** `boolean`.

```lua
if exports.cuxial_diving:IsInCrew(source) then
    -- the player is busy with the diving job
end
```

### GetProfile

Returns the diving level and experience of a character. It works with the character offline too.

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

| Parameter   | Type   | Description                                       |
| ----------- | ------ | ------------------------------------------------- |
| `citizenid` | string | Character identifier, as given by your framework. |

**Returns:** `{ level: number, xp: number }`, or `nil` when the character has no diving profile or the database is not ready.

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

## Finish hook

`server/hooks.lua` is open for editing. Its function `CuxialDiving.hooks.onFinish` runs on the server once for each connected member, right after they are paid for a delivered job.

{% 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 %}

| Parameter     | Type   | Description                                                   |
| ------------- | ------ | ------------------------------------------------------------- |
| `src`         | number | Server id of the player.                                      |
| `data.runId`  | number | Id of the job in the history. `0` when it could not be saved. |
| `data.region` | number | `id` of the region, from `data/regions.lua`.                  |
| `data.score`  | number | Required pieces collected by this player.                     |
| `data.money`  | number | Money paid to this player.                                    |
| `data.xp`     | number | Experience given to this player.                              |
| `data.owner`  | string | Character identifier of the crew owner.                       |

{% hint style="info" %}
The hook does not run for jobs that are reset or cancelled, nor for members who are disconnected at delivery. An error inside it is printed to the console and does not stop the payout.
{% endhint %}

## Boat state

The work boat carries two replicated state bags that other resources can read.

| State bag      | Type    | Description                                                                                                   |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------- |
| `divingAnchor` | boolean | `true` while the anchor is down. Read only: the server restores its own value if another resource changes it. |
| `fuel`         | number  | Fuel level set when the boat spawns, from `boat.fuel`.                                                        |

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

## Money reasons

Payments go through your framework with these reasons, which you can use to filter your own money logs.

| Reason                 | When                                              |
| ---------------------- | ------------------------------------------------- |
| `cuxial-diving`        | Payout of a delivered job.                        |
| `cuxial-diving-daily`  | Reward of a daily task.                           |
| `cuxial-diving-market` | Purchase or sale at the market.                   |
| `cuxial-diving-refund` | Refund of a purchase that could not be delivered. |


---

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