> For the complete documentation index, see [llms.txt](https://tgiann.gitbook.io/tgiann/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tgiann.gitbook.io/tgiann/scripts/tgiann-emotes/hooks.md). Agents can also search and read this documentation through its [MCP server](https://tgiann.gitbook.io/tgiann/~gitbook/mcp).

# Hooks

Hooks let other resources change, cancel or follow what the emote menu does without touching the emotes code.

{% hint style="info" %}
Hooks run on the side they are added on. Client hooks (animations, props, keys, menu, freestyle) are added from a client script, server hooks (shop purchases, animation packs) from a server script.
{% endhint %}

{% hint style="success" %}
`before` hooks run before the action: return `false` to cancel it, return the changed `data` table to change it, or return nothing to leave it as it is. When several resources add the same `before` hook, each one gets the data the previous one returned. `on` hooks run after the action, their return value is ignored.
{% endhint %}

## AddHook

```lua
local hookId = exports["tgiann-emotes"]:AddHook(name, function(data) end)
```

* name: `string` one of the hook names below, an unknown name raises an error
* handler: `function(data)`

Return:

* hookId: `number`

{% hint style="warning" %}
The data reaches your resource as a copy. Changing a field inside your handler does nothing unless you return the table.
{% endhint %}

{% hint style="info" %}
Hooks of a resource are removed automatically when that resource stops. Add them again if tgiann-emotes restarts while your resource keeps running.
{% endhint %}

***

## Client: before hooks

### beforePlay

Triggered before an animation starts on the player, from the menu, the wheel, the command, an export or an animation suggestion. Return `false` to cancel it, or change `name` to play another animation instead.

* Data: `table`
  * name: `string` full animation name, for example `propEmote_selfie` (animation suggestions: `context_<id>` of [configContext.lua](https://tgiann.gitbook.io/tgiann/scripts/tgiann-emotes/configs/configcontext.lua.md))
  * type: `string` animation category: `emote`, `dance`, `propEmote`, `walkStyle`, `expression`, `scenario`, `sharedEmote`, `emoji`, `idleAnimation`
  * options?: `table` play options sent by the menu

**Example**

```lua
-- no animations while handcuffed
exports["tgiann-emotes"]:AddHook("beforePlay", function(data)
    if LocalPlayer.state.isCuffed then return false end
end)
```

***

### beforePropSpawn

Triggered before each prop of an animation spawns, also for the peds of the menu preview. Return `false` to skip the prop, return the changed `data` to spawn another model or placement, or spawn your own entity and return it to use it as the prop (remove it in `onPropRemove`).

* Data: `table`
  * ped: `number`
  * isPlayerPed: `boolean` false for the menu preview peds
  * animation: `string` full animation name
  * slot: `"firstProp" | "secondProp"`
  * prop: `string | number` model
  * bone: `number`
  * placement?: `number[]` `{ x, y, z, rx, ry, rz }`
  * textureVariation?: `number`
  * rotationOrder: `number`
  * noCollision?: `boolean`

**Example**

```lua
-- swap the prop of the umbrella emote for your own model
exports["tgiann-emotes"]:AddHook("beforePropSpawn", function(data)
    if data.prop == "p_amb_brolly_01" then
        data.prop = "my_brand_umbrella"
        return data
    end
end)
```

{% hint style="info" %}
The script ships `client/integrations/phoneAccessories.lua` (not encrypted): every emote with a phone prop puts the player's own decorated phone from tgiann-phone-accessories in their hand. It is a complete example of `beforePropSpawn` returning an entity plus `onPropRemove`.
{% endhint %}

***

### beforePtfx

Triggered when the player uses the effect of an animation (camera flash, smoke and so on). Return `false` to cancel it or change `color`.

* Data: `table`
  * animation: `string` full animation name
  * color?: `table` effect color picked for this use

**Example**

```lua
-- no effects inside the hospital
exports["tgiann-emotes"]:AddHook("beforePtfx", function(data)
    if exports["my-zones"]:IsInside("hospital") then return false end
end)
```

***

### beforeHandsUp / beforePointing / beforeRagdoll

Triggered before the player raises their hands, starts pointing or falls into ragdoll with its key. Return `false` to block it.

* Data: `table` empty

**Example**

```lua
-- no ragdoll while on duty
exports["tgiann-emotes"]:AddHook("beforeRagdoll", function()
    if LocalPlayer.state.onDuty then return false end
end)
```

***

### beforeFreestyle

Triggered before the [freestyle dance](https://tgiann.gitbook.io/tgiann/scripts/tgiann-emotes/guides/freestyle-dance.md) starts (menu card, command or `StartFreestyle`). Return `false` to block it, or change `style`.

* Data: `table`
  * style: `integer` dance style number of `configFreestyle.lua`

**Example**

```lua
-- freestyle only inside the club
exports["tgiann-emotes"]:AddHook("beforeFreestyle", function()
    if not exports["my-zones"]:IsInside("nightclub") then return false end
end)
```

***

### beforeMenuOpen

Triggered before the emote menu or the wheel opens with its key. Return `false` to keep it closed.

* Data: `table`
  * menu: `"main" | "wheel"` `main` covers the full, minimal and quick search menu styles

**Example**

```lua
-- no emote menu while dead
exports["tgiann-emotes"]:AddHook("beforeMenuOpen", function()
    if LocalPlayer.state.isDead then return false end
end)
```

## Client: on hooks

### onPlay

Triggered when an animation starts on the player.

* Data: `table`
  * name: `string` full animation name
  * type: `string` animation category
  * label: `string` animation label
  * options?: `table`

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onPlay", function(data)
    print(("playing %s (%s)"):format(data.label, data.name))
end)
```

***

### onStop

Triggered when the player's animation stops or another one replaces it. Clearing a walk style, an expression or an idle animation triggers it too, with that `type`.

* Data: `table`
  * name: `string` full animation name
  * type: `string` animation category

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onStop", function(data)
    if data.type == "walkStyle" then
        print("walk style back to default")
    end
end)
```

***

### onPropSpawn

Triggered after a prop of an animation was spawned and attached (props a `beforePropSpawn` hook replaced with its own entity are not included).

* Data: `table` the `beforePropSpawn` fields plus:
  * entity: `number` the spawned prop

**Example**

```lua
-- make the player's props half see-through on this client
exports["tgiann-emotes"]:AddHook("onPropSpawn", function(data)
    if data.isPlayerPed then SetEntityAlpha(data.entity, 180, false) end
end)
```

***

### onPropRemove

Triggered when the animation ends, only for the entities your own `beforePropSpawn` returned. Delete your entity here.

* Data: `table` the `beforePropSpawn` fields plus:
  * entity: `number` the entity your hook returned

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onPropRemove", function(data)
    if DoesEntityExist(data.entity) then DeleteEntity(data.entity) end
end)
```

***

### onHandsUp / onPointing / onRagdoll

Triggered when hands up, pointing or ragdoll starts and ends.

* Data: `table`
  * active: `boolean` true when it starts, false when it ends

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onHandsUp", function(data)
    TriggerServerEvent("my-robbery:handsUp", data.active)
end)
```

***

### onFreestyle

Triggered when the freestyle dance starts and stops.

* Data: `table`
  * active: `boolean` true when it starts, false when it stops
  * style?: `integer` dance style, only when it starts

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onFreestyle", function(data)
    TriggerServerEvent("my-club:dancing", data.active)
end)
```

***

### onMenuOpen / onMenuClose

Triggered when the emote menu or the wheel opens and closes.

* Data: `table`
  * menu: `"main" | "wheel"`

**Example**

```lua
-- hide your HUD while the emote menu is open
exports["tgiann-emotes"]:AddHook("onMenuOpen", function(data)
    if data.menu == "main" then exports["my-hud"]:Hide() end
end)

exports["tgiann-emotes"]:AddHook("onMenuClose", function(data)
    if data.menu == "main" then exports["my-hud"]:Show() end
end)
```

## Server: before hooks

### beforeBuyAnimation

Triggered before a player buys an animation in the shop. Return `false` to refuse the purchase, or change `price` / `moneyType`. A `price` of `0` gives it for free.

* Data: `table`
  * source: `number` player server id
  * name: `string` full animation name
  * price: `number`
  * moneyType: `string` account the price is paid from

**Example**

```lua
-- VIP players get 50% off
exports["tgiann-emotes"]:AddHook("beforeBuyAnimation", function(data)
    if IsPlayerAceAllowed(data.source, "vip") then
        data.price = math.floor(data.price * 0.5)
        return data
    end
end)
```

## Server: on hooks

### onBuyAnimation

Triggered after the purchase was paid and saved.

* Data: `table` same fields as `beforeBuyAnimation`, with the price that was paid

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onBuyAnimation", function(data)
    print(("%s bought %s for %s %s"):format(GetPlayerName(data.source), data.name, data.price, data.moneyType))
end)
```

***

### onAnimationsAdded

Triggered after a resource added animations with [AddAnimations](https://tgiann.gitbook.io/tgiann/scripts/tgiann-emotes/exports.md) (an animation pack starting).

* Data: `table`
  * resource: `string` the resource that added them
  * category: `string` category they were added to
  * added: `integer` how many were new (0 when every one was already there)

**Example**

```lua
exports["tgiann-emotes"]:AddHook("onAnimationsAdded", function(data)
    if data.added > 0 then print(("%s added %d %s"):format(data.resource, data.added, data.category)) end
end)
```

## RemoveHook

Removes a hook by the id `AddHook` returned.

```lua
local removed = exports["tgiann-emotes"]:RemoveHook(hookId)
```

* hookId: `number`

Return:

* removed: `boolean`
