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

# Events

This page documents the network events, triggers, and state synchronization mechanisms utilized in AK47 Vehicle Keys (ak47\_vehiclekeys).

### Client Events

#### `ak47_vehiclekeys:policeAlert`

Receives vehicle theft/hotwire/lockpick alerts sent by the server for on-duty law enforcement officers when using the default built-in alert system.

```lua
RegisterNetEvent('ak47_vehiclekeys:policeAlert', function(coords, street, title, vehName, plate)
    -- Displays notification and creates a temporary map blip radius for police/sheriff
end)
```

#### `ak47_vehiclekeys:getkey`

Triggered by server command `/getkey` to generate and award a physical vehicle key to the admin.

#### `ak47_vehiclekeys:getvkey`

Triggered by server command `/getvkey` to generate and award a virtual vehicle key to the admin.

***

### Server Events

#### `ak47_vehiclekeys:setstate`

Updates an entity state bag on a networked vehicle (e.g. `doorslocked`, `hotwired`).

```lua
TriggerServerEvent('ak47_vehiclekeys:setstate', vehNetId, stateName, stateValue)
```

* **`vehNetId`** (`number`): Network ID of the vehicle entity (`VehToNet(vehicle)`).
* **`stateName`** (`string`): The state name key (e.g. `'doorslocked'`, `'hotwired'`).
* **`stateValue`** (`any`): The value to assign (`true`, `false`, etc.).

#### `ak47_vehiclekeys:transferkey`

Transfers a virtual vehicle key from the invoking player to a target player ID.

```lua
TriggerServerEvent('ak47_vehiclekeys:transferkey', plate, targetServerId)
```

* **`plate`** (`string`): Vehicle license plate.
* **`targetServerId`** (`number`): Destination player server ID.

#### `ak47_vehiclekeys:policeAlert`

Dispatches a default built-in police notification to all online police and sheriff players.

```lua
TriggerServerEvent('ak47_vehiclekeys:policeAlert', playerCoords, street, alertTitle, vehName, plate)
```

***

### Entity State Bags

Vehicles managed by `ak47_vehiclekeys` use FiveM Entity State Bags for synchronized state management:

* **`Entity(vehicle).state.doorslocked`** (`boolean`):
  * `true`: Vehicle is locked.
  * `false`: Vehicle is unlocked.
* **`Entity(vehicle).state.hotwired`** (`boolean`):
  * `true`: Vehicle has been successfully hotwired.
