> For the complete documentation index, see [llms.txt](https://docs.rainmad.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rainmad.com/resources/heists-2.0-update/exports.md). Agents can also search and read this documentation through its [MCP server](https://docs.rainmad.com/~gitbook/mcp).

# Exports

Every RAINMAD heist can be started from another script. You can build one tablet, laptop, phone app or NPC that lists every heist, shows which ones are free, and starts them. The heist then runs exactly as it does from its own job giver.

The same exports exist in every heist. Only the resource name changes.

## Two kinds of heist

**Job heists** start when a player takes the job from a job giver (Lester, a boss, a buyer). `startHeist` does the same from anywhere: the same checks (police, cooldown, price, items, crew), then the same notification, blip and route the job giver gives.

Art, Artifact, Betta Bank, Deluxe Car, Drug Boat, Humane Labs, Jailbreak, Kidnapping, Oil Rig, Pacific, Train, Underground, Union, Vangelico, Van, Vault and Yacht.

**On the spot heists** begin with something the player does at the place: a shot at the clerk or the bank, a lock, a card swipe. For these, `startHeist` gives the player a **contract**:

* The place is marked on their map with a route.
* It is held for them for `contractMinutes` (30 by default). Nobody else can start it in that time.
* They go there and start the robbery as usual. The contract ends when they do.

Shop Robbery, Weed Shop, Fleeca, Fleeca Final, Paleto Bank, Vangelico Final and Casino.

**Graffiti War** is a gang war. `startHeist` starts a war, the same as the admin command. It works from the server only.

## Server exports

Call these from your tablet's server side. `source` is the player who starts the heist.

```lua
-- start (job heist), or take a contract (on the spot heist)
local ok, result = exports.rm_paletoheist:startHeist(source)

-- heists with more than one place take the place number
local ok, result = exports.rm_shoprobbery:startHeist(source, 4)

-- can this player start it now? (nothing is shown to the player)
local ok, reason, detail = exports.rm_pacificheist:canStart(source)

-- everything a tablet needs to draw a list
local status = exports.rm_fleecaheist:getStatus()

-- reset one place, every place, or the only place
exports.rm_shoprobbery:resetHeist(4)
exports.rm_shoprobbery:resetHeist('all')
exports.rm_trainheist:resetHeist()
```

`startHeist(source, place?, options?)` returns `true` and the result, or `false`, a reason and sometimes a detail.

* For a job heist, the result is what the heist's own start returns (usually `true`).
* For an on the spot heist, the result is `'contract'`.

Vault Heist needs a crew of three. Pass the crew when it was not formed at Lester:

```lua
exports.rm_vaultheist:startHeist(source, nil, { crew = { source, friend1, friend2 } })
```

### getStatus

```lua
{
    resource = 'rm_fleecaheist',
    name = 'Fleeca Heist',
    mode = 'contract',              -- 'job' | 'contract' | 'admin'
    police = { required = 2, online = 3 },
    locations = {
        {
            id = 1,
            label = 'Legion Square',    -- only when you set one in the data file
            coords = vector3(...),
            state = 'ready',            -- 'ready' | 'active' | 'done'
            cooldown = 0,               -- seconds left
            contract = { player = 12, expiresIn = 1500 },   -- only while a contract is live
        },
        -- ...
    },
}
```

`getStatus(place)` gives the same table with only that place in `locations`.

To give a place a name your tablet can show, add `label = 'Legion Square'` to it in the heist's data file (shops, banks).

### Reasons

| Reason              | Meaning                                                                                                                                       | Detail        |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `busy`              | Someone is robbing it right now.                                                                                                              |               |
| `not_ready`         | It was robbed and has not reset yet.                                                                                                          |               |
| `cooldown`          | It was robbed recently.                                                                                                                       | seconds left  |
| `police`            | Not enough police online.                                                                                                                     | police needed |
| `reserved`          | Another player holds a contract on it.                                                                                                        |               |
| `need_contract`     | `contractOnly` is on and this player has no contract.                                                                                         |               |
| `refused`           | The heist said no: a missing item, not enough money for the price, crew not complete, not enough players around. The player gets the message. |               |
| `location_required` | The heist has more than one place: pass its number.                                                                                           |               |
| `unknown_location`  | No place with that number.                                                                                                                    |               |
| `no_player`         | `source` is not a player in the server.                                                                                                       |               |
| `not_supported`     | The resource is too old to have exports.                                                                                                      |               |
| `disabled`          | A client script called `startHeist`, but `clientExport` is off.                                                                               |               |
| `too_fast`          | A client script called `startHeist` again within 2 seconds.                                                                                   |               |

`canStart` checks the place (state, cooldown, police, contract). For an on the spot heist it answers whether the place can be booked. It cannot know a heist's own rules, such as items, the price or the crew, so `startHeist` can still answer `refused`.

## Client exports

Most tablets are NUI pages on the client. These exports answer from the client:

```lua
local status = exports.rm_pacificheist:getStatus()
local ok, reason = exports.rm_pacificheist:canStart()
local ok, result = exports.rm_pacificheist:startHeist()
```

`getStatus` and `canStart` always work. **`startHeist` from the client is off by default.** A client export can be called by any script running on the player's PC, cheats included. So turn it on only if you accept that a player can skip the walk to the job giver. Police, cooldown, price, items and crew are still checked on the server either way.

```lua
cfg.remoteStart = {
    clientExport = true,
}
```

The safe way is to call the server export from your tablet's own server event:

```lua
-- your tablet, server side
RegisterNetEvent('mytablet:startHeist', function(resource, place)
    local src = source
    if not MyTablet.canUse(src) then return end   -- your own rules
    local ok, reason = exports[resource]:startHeist(src, place)
    if not ok then TriggerClientEvent('mytablet:refused', src, reason) end
end)
```

A client script can never pass `options`, so it cannot pick a crew for Vault Heist.

## Live updates

Every heist sends this event on the server and on every client when a place changes state, so a tablet can update its list without asking again:

```lua
AddEventHandler('rm_heists:state', function(resource, place, state)
    -- state: 'active' (started), 'done' (robbed), 'ready' (reset)
end)
```

## Settings (cfg.lua)

Job heists:

```lua
cfg.remoteStart = {
    showStartPed = true,    -- false hides the job giver and its prompt, when every job starts from your tablet
    clientExport = false,   -- true lets a client script call startHeist
}
```

On the spot heists:

```lua
cfg.remoteStart = {
    contractMinutes = 30,   -- how long a contract holds the place
    contractOnly = false,   -- true: the place can only be robbed by a player holding a contract
    clientExport = false,
}
```

With `contractOnly = true`, the shops, banks and the rest can only be robbed through your tablet.

## Resource names

| Heist                 | Resource              | Places |
| --------------------- | --------------------- | ------ |
| Art Heist             | `rm_artheist`         | 1      |
| Artifact Heist        | `rm_artifactheist`    | 1      |
| Betta Bank Heist      | `rm_bettaheist`       | 1      |
| Casino Heist          | `rm_casinoheist`      | 1      |
| Deluxe Car Heist      | `rm_carheist`         | 1      |
| Drug Boat Heist       | `rm_drugboatheist`    | 1      |
| Fleeca Heist          | `rm_fleecaheist`      | 6      |
| Fleeca Heist Final    | `rm_fleecafinal`      | 6      |
| Graffiti War          | `rm_graffitiwar`      | 1      |
| Humane Labs Heist     | `rm_humanelabsheist`  | 1      |
| Jailbreak             | `rm_jailbreak`        | 1      |
| Kidnapping            | `rm_kidnapping`       | 1      |
| Oil Rig Heist         | `rm_oilrigheist`      | 1      |
| Pacific Heist         | `rm_pacificheist`     | 1      |
| Paleto Bank Heist     | `rm_paletoheist`      | 1      |
| Shop Robbery          | `rm_shoprobbery`      | 18     |
| Train Heist           | `rm_trainheist`       | 1      |
| Underground Heist     | `rm_undergroundheist` | 1      |
| Union Heist           | `rm_unionheist`       | 1      |
| Van Heist             | `rm_vanheist`         | 1      |
| Vangelico Heist       | `rm_vangelicoheist`   | 1      |
| Vangelico Heist Final | `rm_vangelicofinal`   | 1      |
| Vault Heist           | `rm_vaultheist`       | 1      |
| Weed Shop Heist       | `rm_weedshopheist`    | 1      |
| Yacht Heist           | `rm_yachtheist`       | 1      |

Heists with one place need no place number.
