> For the complete documentation index, see [llms.txt](https://tommys-scripts.gitbook.io/fivem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tommys-scripts.gitbook.io/fivem/paid-scripts/tommys-afk-cinematics.md).

# Tommy's AFK Cinematics

{% embed url="<https://youtu.be/mN-2WbAFMvs>" %}

<sub>Video URL:</sub> [<sub>https://youtu.be/mN-2WbAFMvs</sub>](https://youtu.be/mN-2WbAFMvs)

[FiveM Post](https://forum.cfx.re/t/afk-cinematics/5359572) | [Store Page](https://tommy141x.tebex.io/)

<sub>Escrow Encrypted: Yes | Requirements: None</sub>

#### Features

* Smooth Cinematics
* Shuffled Custom Background Music *(optional)*
* Smart Shot Selection (prevents clipping and repetative shots (not always))
* Smart Beat Detection (attempts to cut on beat if music is enabled)
* Add or modify any camera sequence in the configuration
* Configurable AFK detection and triggering

#### Live Test Server

If you would like to test it out yourself, come [check it out](fivem://connect/kqj4l6):

1. Open FiveM & Press F8
2. Type `connect 152.53.89.119` & hit enter.
3. Hop in a vehicle and run the `/afk` command!

### Configuration

#### AFK Detection

* **`Config.Timeout`** (number) - Seconds of inactivity before AFK camera activates. Set to `0` to disable automatic detection.

#### Music Settings

* **`Config.useMusic`** (boolean) - Enable/disable background music during AFK mode.
* **`Config.musicVolume`** (number) - Music volume level (`0.0` to `1.0`).
* **`Config.musicTracks`** (table) - Array of music (ogg) files from the `music/` folder. Randomly selected on AFK start.

#### Camera Sequences

* **`Config.CameraSequences`** (table) - Array of cinematic camera sequences. Each sequence has:
  * `startPos` - Camera cuts to this position
    * `offset` - vector3(x, y, z) relative to vehicle
    * `rotation` - vector3(pitch, roll, yaw) in degrees
    * `fov` - Field of view (number)
    * `dof` - Depth of field {near, far, strength}
  * `endPos` - Camera smoothly animates to this position (5-10 second duration)
    * Same properties as `startPos`

***

### Events

#### `tommys-afk:stateChanged`

Triggered when AFK state changes.

**Parameters:**

* `isAFK` (boolean) - `true` when entering AFK, `false` when exiting

**Example:**

```lua
AddEventHandler('tommys-afk:stateChanged', function(isAFK)
    if isAFK then
        -- Player entered AFK mode
        DisplayRadar(false)
    else
        -- Player exited AFK mode
        DisplayRadar(true)
    end
end)
```

***

### Exports

#### `IsAFK()`

Check if player is currently in AFK mode.

**Returns:** `boolean`

```lua
local afk = exports['tommys-afk']:IsAFK()
```

***

#### `StartAFK()`

Manually start AFK camera (requires player in vehicle).

**Returns:** `boolean` - `true` if started successfully

```lua
exports['tommys-afk']:StartAFK()
```

***

#### `StopAFK()`

Manually stop AFK camera.

**Returns:** `nil`

```lua
exports['tommys-afk']:StopAFK()
```

***

#### `ToggleAFK()`

Toggle AFK mode on/off.

**Returns:** `boolean` - New AFK state after toggle

```lua
local newState = exports['tommys-afk']:ToggleAFK()
```

***

#### `IsAFKEnabled()`

Check if AFK system is enabled for the player.

**Returns:** `boolean`

```lua
local enabled = exports['tommys-afk']:IsAFKEnabled()
```

***

#### `SetAFKEnabled(enabled)`

Enable or disable the AFK system entirely for the player.

**Parameters:**

* `enabled` (boolean) - `true` to enable, `false` to disable

**Returns:** `boolean` - `true` if successful

```lua
exports['tommys-afk']:SetAFKEnabled(false) -- Disable AFK system
```

***

### Commands

#### `/afk`

Manually toggle AFK camera on/off. Must be in a vehicle.

#### `/toggle_afk_cinematics`

Enable/disable the entire AFK system for your session.

***

### Notes

* AFK camera only works when player is in a vehicle
* Camera automatically exits on any input (movement, camera rotation, controls)
* System uses smart sequence selection to avoid obstructions and vehicle clipping (not always)
* Automatic AFK triggers after `Config.Timeout` seconds of inactivity
