# testdrive

Players can test drive any vehicle in the showroom for a configurable duration before deciding to purchase.

***

## Flow

1. Player selects a vehicle in the UI and clicks **Test Drive**.
2. The UI closes automatically.
3. The selected vehicle spawns at `Config.TestDriveSpawn` with plate `TEST`.
4. The player is placed in the driver seat.
5. A countdown timer overlay appears in the top-right corner.
6. When the timer hits zero (or the player ends early), the vehicle is deleted and the player is teleported back to their original position.

***

## Ending a Test Drive

A test drive ends when **any** of the following occur:

| Trigger                                                      | Message shown                   |
| ------------------------------------------------------------ | ------------------------------- |
| Timer expires                                                | `Config.Notify.testDriveEnd`    |
| Player presses end key (`Config.EndTestDriveKey`, default X) | `Config.Notify.testDriveEnd`    |
| Player exits the vehicle                                     | `Config.Notify.testDriveExited` |

***

## Configuration

| Key                           | Description                                   |
| ----------------------------- | --------------------------------------------- |
| `Config.TestDriveDuration`    | Duration in milliseconds                      |
| `Config.TestDriveSpawn`       | Spawn coords + heading for the test vehicle   |
| `Config.EndTestDriveKey`      | FiveM control index (default `73` = X)        |
| `Config.EndTestDriveKeyLabel` | Display label shown in the start notification |

***

## Internals

Three threads run simultaneously during a test drive:

* **Timer thread** — ticks every 1 s, sends `updateTestDriveTimer` to NUI, calls `EndTestDrive()` at zero.
* **Control thread** — polls every frame for the end-key press.
* **Vehicle check thread** — polls every 1 s; ends the drive if the player is no longer inside the test vehicle.

All three threads self-terminate when `testDriveActive` becomes `false`.

***

## Guards

* A second test drive cannot be started while one is already active (`Config.Notify.alreadyDriving`).
* If an invalid car index is received from NUI, the action is rejected silently with a notification.


---

# 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://mohssins.gitbook.io/mohscriptsdocs/moh-vipshowroom/testdrive.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.
