> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-advanced-gang/developers/exports.md).

# Exports

Server and client exports of CAS Advanced Gang System for heist, bounty, war and territory scripts: gangs, permissions, members, tiers and contests.

CAS Advanced Gang System offers a small API for your own heist, bounty, war and territory scripts. Every export reads the server's live state.

## Server

### GetPlayerGang

```lua
local gang = exports["cas-advanced-gang"]:GetPlayerGang(source)
```

Returns the player's gang, or `nil` if they ride with none.

```lua
{
  id = 12, name = 'The Bearclaw Boys', tag = 'BCB', tier = 3,
  rankId = 'enforcer', rankName = 'Enforcer',
  treasury = 4820.50,
  camp = { x = -1234.5, y = 678.9, z = 102.3, influence = 220.0 },
}
```

### HasGangPermission

```lua
local ok = exports["cas-advanced-gang"]:HasGangPermission(source, 'stashWithdraw')  -- boolean
```

Checks the player's rank in their own gang, including the gang's own edits to its ranks. The keys are listed in [Ranks and permissions](/script-documentation/cas-advanced-gang/configuration/ranks.md#permission-keys). `false` for a player with no gang.

### GetGangMembers

```lua
local members = exports["cas-advanced-gang"]:GetGangMembers(gangId)
-- { { charId = '3', name = 'Arthur Morgan', rankId = 'right_hand', online = true }, ... }
```

An empty table for an unknown gang. Pass the numeric `id` from `GetPlayerGang`.

### GetGangTier

```lua
local tier = exports["cas-advanced-gang"]:GetGangTier(gangId)  -- number, 0 for an unknown gang
```

### IsInGangCamp

```lua
local inCamp = exports["cas-advanced-gang"]:IsInGangCamp(source)  -- boolean
```

`true` when the player stands within `Config.CampBounds` of their own camp's centre.

### AddToTreasury

```lua
local ok = exports["cas-advanced-gang"]:AddToTreasury(gangId, amount, who, note)  -- boolean
```

Pays money into a gang's treasury. This is the one to call from a heist or job script.

* Writes a ledger entry under `who` (up to 48 characters) with `note` (up to 120).
* Counts toward the gang's `treasuryEarned` challenge.
* Clears upkeep debt first, like any payment.
* Refreshes every member's open ledger.
* **Pays in only.** An amount of zero or less returns `false`.

```lua
-- a heist script paying the gang's cut
local gang = exports["cas-advanced-gang"]:GetPlayerGang(source)
if gang then
  exports["cas-advanced-gang"]:AddToTreasury(gang.id, 350.0, 'Saint Denis Bank', "The gang's cut of the job")
end
```

{% hint style="warning" %}
`AddToTreasury` adds money to the treasury. It doesn't take it from anyone. If the money should come from a player, take it from them first.
{% endhint %}

### GetGangContest

```lua
local contest = exports["cas-advanced-gang"]:GetGangContest(gangId)
-- { by = 'The Del Lobos', raiders = 3, defenders = 1, since = 1758620000 }, or nil
```

`nil` while the camp isn't contested. `by` is the gang with the most riders inside, and `since` is a unix time. It only reports: what a contest is worth is up to your script. See [Territory, lookout and bell](/script-documentation/cas-advanced-gang/playing/territory.md).

## Client

### OpenGangCreator

```lua
exports["cas-advanced-gang"]:OpenGangCreator()
```

Opens the gang creator, the same as `/creategang`. Use it from your own menu, NPC or prompt.

It's also an event, which the server can send:

```lua
TriggerEvent('bearclaw:client:openGangCreator')                  -- client
TriggerClientEvent('bearclaw:client:openGangCreator', source)   -- server
```
