# Smoke Bunker exports

> Server and client exports for your own resources, with arguments, return values and an example for each.

Call the 15 server exports and 1 client export as `exports.smoke_bunker:<name>(...)`. A bunker id, server id or amount of the wrong type or outside the range returns `false` or `nil` and changes nothing.

## Server

| Export | Returns |
| --- | --- |
| `getBunker(bunkerId)` | Snapshot table, or `nil` |
| `getPlayerBunker(source)` | Bunker id of the player's org, or `nil` |
| `getBunkerBySite(siteKey)` | Bunker id, or `nil` |
| `getInsideBunker(source)` | Bunker id the player stands in, or `nil` |
| `hasResearch(bunkerId, projectId)` | `boolean` |
| `getPerks(bunkerId)` | Perk table, or `nil` |
| `hasPerk(bunkerId, perk)` | `boolean` |
| `addSupplies(bunkerId, units)` | `boolean` |
| `addStock(bunkerId, units, stockType?)` | `boolean` |
| `breakCamera(bunkerId, camId)` | `boolean` |
| `repairCamera(bunkerId, camId)` | `boolean` |
| `finishSupplyRun(bunkerId, success?)` | `boolean` |
| `getMission(bunkerId, slot)` | Mission table, or `nil` |
| `abortMission(bunkerId, slot)` | `boolean` |
| `openBuyerTerminal(source)` | `boolean` |

### `getBunker`

The snapshot is advanced to the current time first, so `supplies`, `stock` and research progress are current.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. `/bunkeradmin list` prints the ids. |

Top-level snapshot fields in 0.10.1:

| Field | What it holds |
| --- | --- |
| `id`, `name`, `orgName`, `orgMode`, `gangName` | Bunker id, site label and org name (both in capitals), `'org'` or `'gang'`, gang name of a gang bunker. |
| `tier` | Facility level: 1 plus business upgrades bought. |
| `balance` | Org funds in whole dollars. |
| `supplies` | Current supplies. |
| `stock` | Total stock of all lines. Fractional: use `math.floor` for whole units. |
| `stockLines`, `line` | One entry per stock type, and the key of the active line. An entry holds the type's `key`, its fields from [`config.stock.types`](/bunker/configuration#supplies-stock-and-production) (`label`, `requires`, `cap`, `speed`, `supplyMult`, `local`, `export`, `cargo`), `unlocked` (bunker can produce it) and `units` (current stock). |
| `rates` | `production`, `producing`, `drain`, `running`, `researching`, `wagesPerHour`, `researchSpeed`, `slots` and `unitsPerHour`. |
| `upgrades`, `custom`, `perks`, `dailyFee` | Business upgrades (`equipment`, `staff`, `security`; `2` means bought), customizations, perk table, daily upkeep. |
| `keypad`, `blastOpen`, `breach`, `alerts` | Current keypad code, blast doors open, breach alert active, unread alert count. |
| `rep`, `repDeals` | Buyer reputation 0 to 100, clean deal count. |
| `camsDown`, `camCount` | Ids of destroyed cameras, camera count. |
| `blueprints`, `projects` | Research blueprints (`name`, `qty`), one entry per research project (`id`, `status`, `progress`, `perHour`). |
| `staff`, `candidates` | Operatives, hire candidates. |
| `members`, `whitelist`, `orgOnline` | Org members, access list, members online. |
| `run`, `delivery`, `missionIdx` | Active supply run, active sale, index of the job shown on the Supplies page. |
| `unpaid`, `wagesOwed` | Wages overdue flag, amount owed. |
| `audit`, `logs`, `income` | Audit trail, recent log lines, daily income of the last 7 days. |
| `opId`, `rangeBest`, `serverTime` | Terminal operator id, best shooting range score, server time in ms. |

```lua server.lua
local bunker = exports.smoke_bunker:getBunker(bunkerId)
if bunker then
    print(('%s has $%s and %s supplies'):format(bunker.orgName, bunker.balance, math.floor(bunker.supplies)))
end
```

### `getPlayerBunker`

| Argument | Type | What it is |
| --- | --- | --- |
| `source` | `number` | Player's server id. |

```lua server.lua
local bunkerId = exports.smoke_bunker:getPlayerBunker(source)
if not bunkerId then return end
```

### `getBunkerBySite`

Returns `nil` when nobody owns the site or `siteKey` is not a string.

| Argument | Type | What it is |
| --- | --- | --- |
| `siteKey` | `string` | Site `key` in `config.sites`, for example `'route68'`. |

```lua server.lua
local bunkerId = exports.smoke_bunker:getBunkerBySite('route68')
```

### `getInsideBunker`

| Argument | Type | What it is |
| --- | --- | --- |
| `source` | `number` | Player's server id. |

```lua server.lua
local bunkerId = exports.smoke_bunker:getInsideBunker(source)
```

### `hasResearch`

Returns `true` when the research project is complete.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `projectId` | `string` | `id` of a project in `config.research.projects`, `'r1'` to `'r6'`. |

```lua server.lua
if exports.smoke_bunker:hasResearch(bunkerId, 'r4') then
    -- the MK2 Suppressor project is done
end
```

### `getPerks` and `hasPerk`

`getPerks` returns a `boolean` for each perk in `config.perks`, or `nil` for an unknown bunker. `hasPerk` returns one of them. `config.perks` sets what grants each perk:

| Perk | `true` when the bunker has |
| --- | --- |
| `workshop`, `exportContracts`, `garage` | Equipment upgrade |
| `blastDoors` | Security upgrade |
| `range` | Shooting Range customization |
| `locker` | Gun Locker customization |
| `quarters` | Personal Quarters customization |
| `caddy` | Transportation customization |

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `perk` | `string` | A key of `config.perks`. |

```lua server.lua
if exports.smoke_bunker:hasPerk(bunkerId, 'workshop') then
    -- the bunker has the Equipment upgrade
end
```

### `addSupplies`

Adds supplies up to the cap in `supplies.max`. Returns `false` for an unknown bunker or an invalid amount.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `units` | `number` | Whole number from `1` to `1000000`. A decimal is rounded down. |

```lua server.lua
exports.smoke_bunker:addSupplies(bunkerId, 25)
```

### `addStock`

Adds units to a stock line, never above its `cap`. Still returns `true` when some or all units do not fit; `false` for an unknown bunker, an invalid amount or an unknown stock type.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `units` | `number` | Whole number from `1` to `1000000`. A decimal is rounded down. |
| `stockType` | `string`, optional | A key of `config.stock.types`: `'ammo'`, `'parts'`, `'precision'` or `'heavy'`. Default: the bunker's active line. |

```lua server.lua
exports.smoke_bunker:addStock(bunkerId, 10, 'parts')
```

### `breakCamera` and `repairCamera`

`breakCamera` destroys a camera. It returns `false` when the bunker does not have that camera or it is already destroyed. Without the Security upgrade a bunker has the first `upgrades.security.baseCams` cameras (2 by default), with it `upgrades.security.cams` (4).

`repairCamera` restores a destroyed camera without using a `camera_part`. It returns `false` when that camera is not destroyed.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `camId` | `string` | `id` of a camera in `config.interior.cams`, for example `'CAM-01'`. |

```lua server.lua
exports.smoke_bunker:breakCamera(bunkerId, 'CAM-01')
exports.smoke_bunker:repairCamera(bunkerId, 'CAM-01')
```

### `finishSupplyRun`

Completes the active supply run. It returns `false` unless `missions.externalRuns` is `true`, and it refuses world mission runs, so it works only with `missions.mode = 'timer'`, the countdown mode with no vehicle. With `externalRuns` on, the built-in timer never completes a run: start your own mission from [`OnSupplyRunStarted`](/bunker/events) and finish it with this export.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `success` | `boolean`, optional | `false` fails the run. Any other value, including leaving it out, completes it. |

```lua server.lua
exports.smoke_bunker:finishSupplyRun(bunkerId, true)
```

### `getMission` and `abortMission`

`getMission` returns a copy of the active world mission in a slot, or `nil`. `abortMission` aborts it and returns `true` when there was a mission to abort.

| Argument | Type | What it is |
| --- | --- | --- |
| `bunkerId` | `number` | Bunker id. |
| `slot` | `string` | `'run'` for a supply run or supply order, `'sale'` for a sale. |

The `getMission` table:

| Field | What it holds |
| --- | --- |
| `id` | Mission id. |
| `kind` | `'order'`, `'source'` or `'sale'`. |
| `risk` | `'LOW'`, `'MED'` or `'HIGH'`. |
| `phase` | `'TRAVEL'`, `'PICKUP'`, `'SEARCH'`, `'FOUND'`, `'LOAD'`, `'DELIVER'` or `'ARRIVE'`. |
| `deadline` | Unix time the mission ends. |
| `controller` | Server id of the member whose client spawns the guards. |
| `netId` | Network id of the mission vehicle, once it exists. |

```lua server.lua
local mission = exports.smoke_bunker:getMission(bunkerId, 'sale')
if mission and mission.risk == 'HIGH' then
    exports.smoke_bunker:abortMission(bunkerId, 'sale')
end
```

### `openBuyerTerminal`

Opens the dealer terminal for a player and returns `true` when it opened. The player must be within `buyer.maxDistance` of a dealer point, unless `buyer.allowAnywhere` is `true`. Returns `false` for a `source` that is not a number or has no character.

| Argument | Type | What it is |
| --- | --- | --- |
| `source` | `number` | Player's server id. |

```lua server.lua
exports.smoke_bunker:openBuyerTerminal(source)
```

### Item use

`smoke_bunker.usePlaceable` is the `server.export` of the four placeable items in `install/items_ox.lua`. The inventory calls it when a player uses one; it is not for your own scripts.

## Client

| Export | Returns |
| --- | --- |
| `getInsideSite()` | Site key of the bunker the local player is in, or `nil` |

### `getInsideSite`

`getInsideSite()` takes no arguments.

```lua client.lua
local siteKey = exports.smoke_bunker:getInsideSite()
if siteKey then
    -- the player is inside a bunker
end
```
