# Listeners

**What are listeners?**\
Listeners are function references that get triggered when a specific action is done by the system, and can be registered on the `Server Side Only`\
\
**Available Listeners**\
These are the current listeners available to you

* onTerritoryChange
* onSpray
* onWarKill
* onWarStarted
* onWarEnd
* onActivityCompletion
* onNeutralZoneCapture
* onTrapHouseBought
* onTrapHouseSold
* onTrapHouseUpgrade
* onTrapHouseDowngrade
* onHookerHire
* onHookerFire
* onDrugSlingerPurchase
* onDrugSlingerSell
* onDrugSlingerDrugSell

**Example**

```lua
local listener = exports['veil-gangs']:registerListener('onSpray', function(payload)
    print('Spray event received')
    print(payload)
    if (type(payload) == 'table') then
        for k,v in pairs(payload) do
            print(k,v)
        end
    end
end)
```

This outputs the following

```lua
Spray event received
table: 00000000495CF7C0
spray_id 4
enemyGang
inEnemyTurf      false
gang     ballas
coords   vec3(1717.445923, 2142.495361, 83.245163)
source   1
```

The following are the listeners and the data they provide

```lua
# onTerritoryChange -> [gangId: string, territoryId: string, zoneData: { points: { [1] = {vector3}, ... }, id: string }]
# onSpray -> [spray_id: number, enemyGang?: string, inEnemyTurf: boolean, gang: string, coords: vector3, source: number]
# onWarKill -> [attacker: string, victim: string, warid: string, attacking_gang: string, defending_gang: string]
# onWarStarted -> [attacker: string, defender: string, details: { attacker: string, defender: string, requestedby: string, gang: string, active: boolean, started: string, endtime: string, terms: { turf: yes|no, money: number, turfdata?: { offering: string, wanting: string }, notoriety: number } }, winindicator: { kills: number, sprays: number }, warid: string]
# onWarEnd -> [warid: string, winner: string, reason: string, serverEnded?: boolean]
# onActivityCompletion -> [gang: string, activity: string, source: number, reward: { notoriety, money }]
# onNeutralZoneCapture -> [gangId: string, territoryId: string, zoneData: { id: string, zoneName: string, points: { [1] = { x: number, y: number: z: number }, thickness: number]
# onTrapHouseBought -> [gangId: string, territoryId: string, houseData: table, houseId: string]
# onTrapHouseSold -> [gangId: string, houseId: string, worth: number]
# onTrapHouseUpgrade -> [gangId: string, houseId: string, upgradeType: string, extraId: string | nil, info: string | table | nil]
# onTrapHouseDowngrade -> [gangId: string, houseId: string, upgradeType: string, extraId: string | nil]
# onHookerHire -> [source: number, gang: string, terid: string, coords: { x: number, y: number, z: number, w: number }, gender: string]
# onHookerFire -> [source: number, gang: string, terid: string]
# onDrugSlingerPurchase -> [source: number, gang: string, terid: string, coords: { x: number, y: number, z: number, w: number }]
# onDrugSlingerSell -> [source: number, gang: string, terid: string]
# onDrugSlingerDrugSell -> [seller: ped, buyer: ped, item: string, count: number, money: number, gang: string, terid: string]
```


---

# Agent Instructions: 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:

```
GET https://veil-development.gitbook.io/veil-development-documentation/paid-resources/gang-system/listeners.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
