> For the complete documentation index, see [llms.txt](https://docs.lostdev.store/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lostdev.store/territories/events-and-exports.md).

# Events and Exports

## Exports

Declared in [`fxmanifest.lua`](broken://pages/5ba0a06311cd48676afb81a11fbe96ec71c1d135). Note: not every name listed in the manifest has an actual implementation — those marked ⚠️ are declared but have no matching `exports(...)` call in the code that was read.

<table><thead><tr><th width="214">Export</th><th>Where</th><th width="182">Signature</th><th>Description</th></tr></thead><tbody><tr><td><code>GetTerritory</code></td><td>server/main.lua</td><td><code>(territoryId) -> table|nil</code></td><td>Full state of a territory.</td></tr><tr><td><code>GetTerritories</code></td><td>server/main.lua</td><td><code>() -> table&#x3C;string, table></code></td><td>Deep copy of every territory's state.</td></tr><tr><td><code>GetTerritoryOwner</code></td><td>server/main.lua</td><td><code>(territoryId) -> string|nil</code></td><td>Identifier of the owning faction.</td></tr><tr><td><code>IsPlayerInsideTerritory</code></td><td>server/main.lua</td><td><code>(source, territoryId) -> boolean</code></td><td>Whether the player is inside the zone.</td></tr><tr><td><code>IsTerritoryContested</code></td><td>server/main.lua</td><td><code>(territoryId) -> boolean</code></td><td>Whether it's contested.</td></tr><tr><td><code>GetCurrentTerritory</code> ⚠️</td><td>—</td><td>—</td><td>Declared in the manifest, no implementation found.</td></tr><tr><td><code>IsInsideTerritory</code> ⚠️</td><td>—</td><td>—</td><td>Same.</td></tr><tr><td><code>GetTerritoryProgress</code> ⚠️</td><td>—</td><td>—</td><td>Same — use <code>GetTerritory(id).progress</code> as an alternative.</td></tr><tr><td><code>StartCapture</code> ⚠️</td><td>—</td><td>—</td><td>Same — captures are started via event, not export.</td></tr><tr><td><code>StopCapture</code> ⚠️</td><td>—</td><td>—</td><td>Same.</td></tr><tr><td><code>SetTerritoryOwner</code> ⚠️</td><td>—</td><td>—</td><td>Same — use <code>Admin.SetOwner</code> internally or the admin event.</td></tr><tr><td><code>ResetTerritory</code> ⚠️</td><td>—</td><td>—</td><td>Same.</td></tr></tbody></table>

### Usage example (from another resource)

```lua
local territory = exports['ld_territories']:GetTerritory('grove')
if territory then
    print(('Grove Street is owned by: %s (%.1f%%)'):format(territory.owner or 'neutral', territory.progress))
end

local isInside = exports['ld_territories']:IsPlayerInsideTerritory(source, 'grove')
```

## Network events — Client → Server

| Event                                     | Payload                                         | Description                                                      |
| ----------------------------------------- | ----------------------------------------------- | ---------------------------------------------------------------- |
| `territories:requestTerritoryData`        | `source?`                                       | Requests the state of every territory.                           |
| `territories:requestMyGroup`              | —                                               | Requests the player's own faction (gang/job).                    |
| `territories:requestCurrentTerritoryData` | —                                               | Requests an update for the player's current territory.           |
| `territories:requestAllTerritories`       | —                                               | Requests the state of every territory (variant).                 |
| `territories:getTerritoryInfo`            | `territoryId`                                   | Requests detail for a specific territory (used by the HUD poll). |
| `territories:playerEntered`               | `territoryId`                                   | Registers the player's entry; may auto-start a capture.          |
| `territories:playerExited`                | `territoryId`                                   | Registers the player's exit.                                     |
| `territories:startCapture`                | `territoryId`                                   | Requests a manual capture start.                                 |
| `territories:requestTabletExtras`         | —                                               | Requests faction stats + activity feed (tablet).                 |
| `territories:requestTerritoryHistory`     | `territoryId`                                   | Requests the history for a territory (tablet).                   |
| `territories:admin:requestData`           | —                                               | Requests admin panel data (authorization + list).                |
| `territories:admin:setOwner`              | `territoryId, owner, reason?`                   | Forces the owner (admin).                                        |
| `territories:admin:setProgress`           | `territoryId, progress, reason?`                | Forces progress 0-100 (admin).                                   |
| `territories:admin:resetTerritory`        | `territoryId, reason?`                          | Full reset to neutral (admin).                                   |
| `territories:admin:setCooldown`           | `territoryId, duration, reason?`                | Forces a cooldown (admin).                                       |
| `territories:admin:clearCooldown`         | `territoryId, reason?`                          | Clears the cooldown (admin).                                     |
| `territories:admin:createZone`            | `{ label, description, radius, owner, coords }` | Creates a new territory (admin).                                 |
| `territories:admin:deleteZone`            | `territoryId`                                   | Deletes a custom territory (admin).                              |

## Network events — Server → Client

| Event                                             | Scope                                      | Payload                                                         | Description                                   |
| ------------------------------------------------- | ------------------------------------------ | --------------------------------------------------------------- | --------------------------------------------- |
| `territories:receiveTerritoryData`                | Single player or broadcast                 | `table<string, table>`                                          | Full state of every territory.                |
| `territories:receiveMyGroup`                      | Single player                              | `{ type, name, label }\|nil`                                    | Player's faction (for blip blacklisting).     |
| `territories:blipSync`                            | Broadcast                                  | `territoryId, { owner, state, isContested, contestedFactions }` | Lightweight update to refresh blips map-wide. |
| `territories:updateTerritoryInfo`                 | Single player                              | Territory detail                                                | HUD update (poll).                            |
| `territories:receiveAllTerritories`               | Single player                              | `table<string, table>`                                          | Variant of `receiveTerritoryData`.            |
| `territories:syncTerritoryState`                  | Players inside                             | `territoryId, state`                                            | Incremental state sync.                       |
| `territories:contestedStateChanged`               | Players inside                             | `territoryId, contested`                                        | Contested state started/ended.                |
| `territories:ownerChanged`                        | Players inside                             | `territoryId, newOwner, oldOwner`                               | Owner change.                                 |
| `territories:captureCompleted`                    | Players inside                             | `territoryId, newOwner`                                         | Capture completed.                            |
| `territories:underAttack`                         | Owning faction (online, map-wide)          | `{ territoryId, label, message, attacker, attackerLabel }`      | Attack alert.                                 |
| `territories:captureResult`                       | Winning/losing factions (online, map-wide) | `{ territoryId, label, result }`                                | Final result ('won'/'lost'), plays sound.     |
| `territories:notify` / `territories:notification` | Single player                              | `message, type`                                                 | Generic notification.                         |
| `territories:receiveTabletExtras`                 | Single player                              | `{ myFactionId, myFactionLabel, activity, stats }`              | Tablet stats payload.                         |
| `territories:receiveTerritoryHistory`             | Single player                              | `{ territoryId, history }`                                      | History for a territory.                      |
| `territories:admin:receiveData`                   | Single player                              | `{ authorized, territories, config }`                           | Admin panel response.                         |
| `territories:admin:zoneCreated`                   | Single player                              | `{ success, id, error }`                                        | Result of zone creation.                      |

## Internal events (server, local `TriggerEvent`)

These never travel over the network — they're used to decouple modules within the same server process (e.g. `server/persistence.lua` reacts to `territories:database:saveTerritoryData` fired by `server/main.lua`).

* `territories:database:initialize`
* `territories:database:saveTerritoryData`
* `territories:captureStarted` / `:captureProgress` / `:captureCompleted`
* `territories:contested` / `:contestedEnded`
* `territories:ownerChanged` / `:ownerLost` / `:defended`
* `territories:cooldownStarted` / `:cooldownEnded`
* `territories:reward:money` / `:reward:item` / `:reward:experience` — **no built-in handler**; implement your own listener if you want capture rewards to actually be delivered (see [Territories § rewards](broken://pages/f5f562e03d137b96e09a107d3fa511d6208e8d30#rewards)).

## NUI callbacks (client)

Registered in `client/main.lua` (`RegisterNuiCallback`) — called from React via `utils/nui.js` (`postNUI`).

| Callback                                                                              | Payload                                         | Effect                                                            |
| ------------------------------------------------------------------------------------- | ----------------------------------------------- | ----------------------------------------------------------------- |
| `nui:ready`                                                                           | —                                               | Confirms the NUI iframe exists; the client sends the locale.      |
| `startCapture`                                                                        | `{ territoryId }`                               | Forwards to `territories:startCapture`.                           |
| `getTerritoryData`                                                                    | —                                               | Returns the player's current territory.                           |
| `hideNUI` / `showNUI`                                                                 | —                                               | Controls the passive HUD.                                         |
| `tablet:open` / `tablet:close`                                                        | —                                               | Opens/closes the tactical tablet.                                 |
| `ui:playSound`                                                                        | `{ sound }`                                     | Plays a sound from `Config.Sounds`.                               |
| `tablet:requestExtras`                                                                | —                                               | Forwards to `territories:requestTabletExtras`.                    |
| `tablet:requestTerritoryHistory`                                                      | `{ territoryId }`                               | Forwards to `territories:requestTerritoryHistory`.                |
| `admin:getCurrentCoords`                                                              | —                                               | Returns the player's current position (for the create-zone form). |
| `admin:requestData`                                                                   | —                                               | Forwards to `territories:admin:requestData`.                      |
| `admin:setOwner` / `setProgress` / `resetTerritory` / `setCooldown` / `clearCooldown` | matching the corresponding admin event          | Forwards to the respective admin event.                           |
| `admin:createZone`                                                                    | `{ label, description, radius, owner, coords }` | Forwards to `territories:admin:createZone`.                       |
| `admin:deleteZone`                                                                    | `{ territoryId }`                               | Forwards to `territories:admin:deleteZone`.                       |


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.lostdev.store/territories/events-and-exports.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
