> For the complete documentation index, see [llms.txt](https://docs.xeutrino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xeutrino.com/api-reference/script-events.md).

# Script events (TSE)

Network script events (commonly referred to as **Trigger Server Events** or **TSE**) are the primary mechanism used by GTA V's online scripts (`freemode`) to synchronize actions, remote interactions, and network triggers between players.

Nexus provides thread-safe TSE functions that execute within the proper `freemode` script context, automatically copying arguments and dispatching via the game's native event sender (`_SEND_TU_SCRIPT_EVENT_NEW`).

***

## Functions

### `send_tse(event_data, player_bits[, event_hash, hash_prefix, event_group])`

### `SendTSE(event_data, player_bits[, event_hash, hash_prefix, event_group])`

Sends a Trigger Server Event to the specified player bitmask.

| Param         | Type    | Description                                                                                                                                                                       |
| ------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `event_data`  | table   | Array of integer arguments (1–64 fields).                                                                                                                                         |
| `player_bits` | integer | Target player bitmask (`1 << player_index` for a specific player, or `0xFFFFFFFF` / `-1` for everyone).                                                                           |
| `event_hash`  | integer | *(optional)* Event JOAAT hash / ID. Defaults to `event_data[1]` if omitted.                                                                                                       |
| `hash_prefix` | boolean | *(optional)* If `true`, automatically assigns `f_0 = event_hash` and `f_1 = PLAYER_ID()`. Set to `true` for 56-field FMMC events, or `false` (default) for direct payload events. |
| `event_group` | integer | *(optional)* Network event group. Default `1`.                                                                                                                                    |

**Returns:** `boolean` (`true` if successfully dispatched to the queue, `false` otherwise).

> **Note on alternative parameter syntax:** For convenience and C++ parity, `send_tse(event_group, event_data, player_bits, event_hash, hash_prefix)` is also accepted.

***

### `send_tse_to_player(target_player, event_data[, event_hash, hash_prefix])`

### `SendToPlayer(target_player, event_data[, event_hash, hash_prefix])`

Sends a TSE directly to a specific target player index (`0`–`31`).

| Param           | Type    | Description                                                                                     |
| --------------- | ------- | ----------------------------------------------------------------------------------------------- |
| `target_player` | integer | Target player index (`0` to `31`).                                                              |
| `event_data`    | table   | Array of integer arguments (1–64 fields).                                                       |
| `event_hash`    | integer | *(optional)* Event JOAAT hash / ID. Defaults to `event_data[1]` if omitted.                     |
| `hash_prefix`   | boolean | *(optional)* When `true`, automatically populates sender ID and hash prefixes. Default `false`. |

**Returns:** `boolean` (`true` if successfully dispatched, `false` otherwise).

***

### `send_tse_to_all(event_data[, event_hash, hash_prefix])`

### `SendToAll(event_data[, event_hash, hash_prefix])`

Broadcasts a TSE event to all players in the session (`0xFFFFFFFF`).

| Param         | Type    | Description                                                                                     |
| ------------- | ------- | ----------------------------------------------------------------------------------------------- |
| `event_data`  | table   | Array of integer arguments (1–64 fields).                                                       |
| `event_hash`  | integer | *(optional)* Event JOAAT hash / ID. Defaults to `event_data[1]` if omitted.                     |
| `hash_prefix` | boolean | *(optional)* When `true`, automatically populates sender ID and hash prefixes. Default `false`. |

**Returns:** `boolean` (`true` if successfully dispatched, `false` otherwise).

***

### `send_script_event(event_data, player_bits[, event_group])`

Legacy raw script event dispatcher.

| Param         | Type    | Description                                                                |
| ------------- | ------- | -------------------------------------------------------------------------- |
| `event_data`  | table   | Array of integer arguments (1–32 fields). First element is the event hash. |
| `player_bits` | integer | Player bitmask (`1 << index`, or `-1`).                                    |
| `event_group` | integer | *(optional)* Event group. Default `1`.                                     |

***

## Event Structure Conventions

In GTA V's 1.56/1.60 network protocol, script events generally follow two patterns:

1. **Small Payload Events** (`hash_prefix = false`, default):
   * Handlers read the payload starting at index 1 directly (e.g. `event_data[1]` is the event ID / sub-action).
   * Used for CEO/Organization actions (e.g., hash `1742713914`), sound triggers, stat events, and notifications.
2. **Large FMMC / Session Events** (`hash_prefix = true`):
   * Handlers expect `f_0` to be the event hash and `f_1` to be the sender's player ID (`PLAYER_ID()`).
   * Used for session kicks (hash `154`), force invites (hash `153`), and apartment warps.

***

## Examples

### 1. Send CEO Kick to the Selected Player

```lua
local target = get_selected_player()
local CEO_KICK_HASH = 1742713914

-- args: { event_hash, sender_id, reason }
local args = { CEO_KICK_HASH, PLAYER_ID(), 0 }
local success = send_tse_to_player(target, args, CEO_KICK_HASH, false)

if success then
    notify("CEO Kick sent to player " .. target)
end
```

### 2. Send Session Kick to All Other Players

```lua
local target = get_selected_player()
local SESSION_KICK_HASH = 0x56E05E1F -- Or relevant event hash

-- For 56-field events using hash_prefix:
local args = {}
for i = 1, 56 do args[i] = 0 end
args[17] = target -- Target slot

-- hash_prefix=true will automatically fill args[1] with hash and args[2] with PLAYER_ID()
send_tse_to_player(target, args, SESSION_KICK_HASH, true)
```

### 3. Broadcast Event to Everyone in Session

```lua
local EVENT_HASH = 123456789
local args = { EVENT_HASH, PLAYER_ID(), 1, 0 }

send_tse_to_all(args, EVENT_HASH, false)
```


---

# 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.xeutrino.com/api-reference/script-events.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.
