# General Events

This page explains the available events for the **r\_grab** script and their usage. These events allow you to interact with the script programmatically from other resources.

### 1. Client-Side Events

#### **1.1 Grab or Release a Player**

**Event Name:** `r_grab:client:grabPlayer`

**Description:** This event allows grabbing or releasing a target player.

**Parameters:**

* `targetId` *(integer)*: The server ID of the player to grab.

***

#### **1.2 Put the Grabbed Player in a Vehicle**

**Event Name:** `r_grab:client:putPlayerInVehicle`

**Description:** Places the currently grabbed player into the nearest vehicle.

***

#### **1.3 Remove the Grabbed Player from a Vehicle**

**Event Name:** `r_grab:client:removePlayerFromVehicle`

**Description:** Removes the currently grabbed player from the vehicle they are in.

***

### 2. Server-Side Events

#### **2.1 Initiate Grab Action**

**Event Name:** `r_grab:server:grabPlayer`

**Description:** Initiates the grab action for a target player, ensuring the source and target are within range.

**Parameters:**

* `targetId` *(integer)*: The server ID of the player being grabbed.

**Notes:**

* The function checks if the target ID is valid.
* It verifies if the source player is within a 10.0 unit range of the target.
* If conditions are met, it triggers client-side events to update both players.

***

### 3. Example Usage

Below is an example of how to use these events in your script:

```lua
-- [[ Grab or release a player ]]
-- Client to server
TriggerServerEvent('r_grab:server:grabPlayer', 1)
-- Server to client
TriggerClientEvent('r_grab:client:grabPlayer', source, 1)

-- [[ Put the grabbed player in a vehicle ]]
-- Only server to client
TriggerClientEvent('r_grab:server:putPlayerInVehicle', source)

-- [[ Remove the grabbed player from the vehicle ]]
-- Only server to client
TriggerClientEvent('r_grab:client:removePlayerFromVehicle', source)
```


---

# 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://docs.rytrak.fr/scripts/advanced-police-grab-ped/general-events.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.
