# Territories

> This script features a territory control system that uses points to determine which gang dominates a specific area. Points are gained or lost through various in-game events, you also have client exports you can trigger from your own scripts.

{% hint style="info" %}
You can find a list of default events that triggers the add/removal of zone points in `server/editable/_territories.lua` I don't list them here to prevent any possible metagaming.
{% endhint %}

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2F9xnEiG9j7ib5xLqRWSln%2Fimage.png?alt=media&#x26;token=cb03fc52-2030-4aad-aed6-0d3b1bbb6e7d" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can hide the left leaderboard in `config/territories.lua`
{% endhint %}

### Territory Colors

> Gangs can set their own territory color in Settings tab > Gang Color, this option will also change the UI color to match their gang style.

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2F4TwAjK5g1kqMlsOCYsZN%2Fimage.png?alt=media&#x26;token=de0e92cf-fea9-4f33-9123-d6c267c08f37" alt=""><figcaption></figcaption></figure>

### Exports

{% tabs %}
{% tab title="Client" %}

### getZone()

> Retrieves the gang that controls the zone where player is standing.
>
> **returns**
>
> * **result**: `string | false` Gang name or false if the zone isn't controlled by any gang
>
> ```lua
> local controlled = exports['av_gangs']:getZone()
> print(controlled)
> ```

### myZone()

> Returns true if the current zone is controlled by the player gang or false.
>
> **returns**
>
> * **result**:`boolean`
>
> ```lua
> local myZone = exports['av_gangs']:myZone()
> print(myZone)
> ```

### addZoneXP(amount)

> Add the desired points to the zone where the player is standing.
>
> **params:**
>
> * **amount**:`number` Amount of points to add to zone.
>
> ```lua
> local toAdd = 10
> exports['av_gangs']:addZoneXP(toAdd) -- will add 10 points to current zone
> ```

### removeZoneXP(amount)

> Remove points to the zone where the player is standing.
>
> **params:**
>
> * **amount**:`number` Amount of points to remove from zone
>
> ```lua
> local toRemove = 5
> exports['av_gangs']:removeZoneXP(toRemove) -- will remove 5 points to zone
> ```

{% endtab %}

{% tab title="Server" %}
{% hint style="info" %}
Zone names can only be retrieved client side, here's a list of names: <https://docs.fivem.net/natives/?_0xCD90657D4C30E1CA>
{% endhint %}

### addZonePoints(gang,zone,amount)

> Add points for a gang to a specific zone.
>
> **params**:
>
> * **gang**:`string` Gang name
> * **zone**:`string` Zone name
> * **amount**:`number` Amount of points to add to territory
>
> **returns**
>
> * **result**:`boolean`
>
> ```lua
> local gang = 'lossantosvagos'
> local zone = 'DAVIS'
> local amount = 10
> local added = exports['av_gangs']:addZonePoints(gang,zone,amount)
> print('added?', added)
> ```

### removeZonePoints(gang,zone,amount)

> Remove gang points from a territory.
>
> **params:**
>
> * **gang**:`string` Gang name
> * **zone**:`string` Zone name
> * **amount**:`number` Amount of points to remove
>
> **returns:**
>
> * **result**:`boolean`
>
> ```lua
> local gang = "lossantosvagos"
> local zone = "DAVIS"
> local amount = 5
> local removed = exports['av_gangs']:removeZonePoints(gang,zone,amount)
> print('removed?', removed)
> ```

### getZoneGang(zone)

> Returns the gang with the most points in the zone.
>
> **params:**
>
> * **zone**:`string` Zone name
>
> **returns:**
>
> * **gang**:`null | string` Returns the gang name or null if zone does not exist or zone isn't controlled by anyone.
>
> ```lua
> local zone = "VINE"
> local topGang = exports['av_gangs']:getZoneGang(zone)
> print('topGang?', topGang)
> ```

{% endtab %}
{% endtabs %}
