# Setup

## Installation

1. **Download & Extract**: Place the script in your `resources` folder
2. **Note:** Ensure that [**xsound** ](https://github.com/Xogy/xsound/archive/refs/tags/1.4.3.zip)is installed and running. *(Required Dependency)*
3. **Add to Server CFG**: Add `ensure cs_carplay` & `ensure xsound` in your `server.cfg`
4. **Configure Settings**: Modify `config.lua` as needed
5. **Add Inventory Items `(Only QB & ESX) (Optional)`**:
   * **Ox Inventory:** Add the following to `ox_inventory/data/items.lua`:

     ```lua
     ['carplay'] = {
         label = 'Car Play',
         weight = 500,
         stack = false,
         description = "A CarPlay device"
     },
     ['radioinstaller'] = {
         label = 'Radio Installer',
         weight = 500,
         stack = false,
         description = "Used to install CarPlay devices into vehicles"
     },
     ```
   * **QB Inventory:** Add the following to `qb-core/shared/items.lua`:

     ```lua
     ["carplay"] = { 
         name = "carplay", 
         label = "Car Play", 
         weight = 500, 
         type = "item", 
         image = "carplay.png", 
         unique = true, 
         useable = true, 
         shouldClose = true, 
         description = "A CarPlay device"
     },
     ["radioinstaller"] = { 
         name = "radioinstaller", 
         label = "Radio Installer", 
         weight = 200, 
         type = "item", 
         image = "radioinstaller.png", 
         unique = false, 
         useable = true, 
         shouldClose = true, 
         description = "Used to install CarPlay devices into vehicles." 
     },

     ```
   * **ESX Inventory:** Run the following SQL query in your database:

     ```lua
     INSERT INTO items (name, label, weight, rare, can_remove) VALUES 
     ('carplay', 'Car Play', 1, 0, 1),
     ('radioinstaller', 'Radio Installer', 1, 0, 1);
     ```

## Configuration

Modify the `config.lua` file to customize the script:

#### General Framework Settings

```lua
CodeStudio.ServerType = 'QB'  -- Choose the framework:
                              -- 'QB' for QBCore Framework
                              -- 'ESX' for ESX Framework
                              -- false for Standalone Mode
```

## Car Play Access

<figure><img src="/files/HELw53uzyauCq3KOkdIx" alt=""><figcaption></figcaption></figure>

* **UseWithCommand** → Enables or disables CarPlay activation using a chat command (default: `/carplay`). If enabled, players can type the command to open CarPlay.
* **UseWithKey** → Allows players to open CarPlay using a keybind (default: `J`). If disabled, the keybind will not work.
* **UseWithItem** → Restricts CarPlay usage to an inventory item (`carplay`). If enabled, players must have the item in their inventory to use CarPlay.
* **Restrict\_Radio** → Limits CarPlay access to specific **jobs, gangs, Ace permissions, or Discord roles**. If left empty, everyone can use it.
* **RadioInstall** → Requires mechanics to **install CarPlay in vehicles manually** before it can be used. Optionally, this can be restricted to **only player-owned vehicles** and requires specific items (`carplay` and `radioinstaller`)

## Extra Options

<figure><img src="/files/A6qSGYberVcLIWLus2IH" alt=""><figcaption></figcaption></figure>

## Discord Logs

<figure><img src="/files/OebnxURro7gwpemo6Qt9" alt="" width="375"><figcaption></figcaption></figure>

Every time a player plays music in CarPlay, it will **send a log message** to the specified Discord channel

## Default Playlist

<figure><img src="/files/MGttTJi2OLd6Bvm7zMtM" alt="" width="563"><figcaption></figcaption></figure>

When players open CarPlay, they will see these **preloaded songs** and can play them instantly

## Restriction System

<figure><img src="/files/XNYtqIqNzYwj2BQbpU9A" alt="" width="563"><figcaption></figcaption></figure>

This setting controls **which vehicles can or cannot** use the **CarPlay system**. You can either **blacklist** (block) or **whitelist** (allow only specific vehicles).

## Free Google AI Integration → [Click For Tutorial Guide](https://youtu.be/Gu3L9mqwBYc?si=8C3qtkLEtrymhky7)

<figure><img src="/files/aAv0vACJOQPgJj45yRML" alt=""><figcaption></figcaption></figure>

* **`EnableAIChat = false`** → Enables or disables AI chat inside CarPlay.
* **`apiKey = "YOUR_GOOGLE_GEMINI_API_KEY"`** → Replace with your **Google Gemini API key** to activate AI chat.
* **`model = "gemini-2.0-flash"`** → AI model to use (`"gemini-1.5-pro"` for better responses).


---

# 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://codestudio5m.gitbook.io/codestudio/our-scripts/car-radio-car-play-pro/setup.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.
