> For the complete documentation index, see [llms.txt](https://ccfivem.gitbook.io/ccfivem-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ccfivem.gitbook.io/ccfivem-docs/vehicles/vehicle-keys-cc_keys.md).

# Vehicle Keys (cc\_keys)

A key ring with its own interface: lock and unlock vehicles, start the engine, lend keys for a limited time and take them back. Owned vehicles are loaded from your framework's vehicle table; lent and temporary keys (e.g. test drives) expire automatically.

**Frameworks:** ESX Legacy, QBCore, QBox (detected automatically, see Framework Bridge).

## Features

* Lock/unlock (L), engine on/off (U) and key ring (F3), rebindable in the FiveM key settings
* Lock feedback: indicator flash, key fob sound, optional horn, door sound
* Engine only starts with a key (configurable)
* Origin per key: owned, borrowed or temporary
* Vehicle location and condition shown on the key ring (with cc\_garage/00%20Overview\.md))
* Lend keys with an expiry time and a borrower limit per vehicle; borrowers cannot pass keys on
* Master jobs (default `police`, `mechanic`) can open every vehicle
* All keys are revoked when a vehicle is sold or transferred
* Anti-dupe: keys grant access, not vehicles; only the registered owner may lend; all checks run on the server with rate limiting
* Exports for other scripts: `HasKeys`, `GiveKeys`, `RemoveKeys`, `RevokeAll`

Scripts such as cc\_garage/00%20Overview\.md), cc\_vehicleshop/00%20Overview\.md), cc\_fuel/00%20Overview\.md) and cc\_licenses/00%20Overview\.md) hand out keys through these exports and keep working without cc\_keys.

## Optional integrations

| Resource                                     | Effect                                          |
| -------------------------------------------- | ----------------------------------------------- |
| cc\_garage/00%20Overview\.md)                | Maintains vehicle positions and spawns vehicles |
| cc\_images%20(cc\_images)/00%20Overview\.md) | Vehicle images; otherwise a car icon            |
| cc\_lib/00%20Overview\.md)                   | Shared notification style                       |

{% hint style="info" %}
The script is protected by Cfx asset escrow. `config/`, `locales/` and the framework bridge files in `shared/` remain editable.
{% endhint %}

## Pages

* Installation
* Configuration
* API
* FAQ

Need help? See Support.

## Installation

See also the general installation guide and dependencies.

### Requirements

| Resource                           | Required | Purpose                                                                  |
| ---------------------------------- | -------- | ------------------------------------------------------------------------ |
| `oxmysql`                          | Yes      | Vehicle table and positions (declared as `dependency` in the fxmanifest) |
| ESX Legacy / QBCore / QBox         | Yes      | Player, job, ownership                                                   |
| `cc_lib`, `cc_images`, `cc_garage` | Optional | See overview                                                             |

### Steps

1. Copy the folder to `resources/[crankchaos]/cc_keys`.
2. Add to your `server.cfg`:

```cfg
ensure oxmysql
ensure es_extended      # or qb-core / qbx_core
ensure cc_lib           # optional
ensure cc_images        # optional
ensure cc_keys
ensure cc_garage        # optional, after cc_keys
```

3. Restart the server.

{% hint style="info" %}
Start cc\_keys **before** scripts that hand out keys (cc\_garage, cc\_vehicleshop, cc\_fuel, cc\_licenses).
{% endhint %}

### Database

No SQL file needs to be imported. The table `cc_vehicle_positions` is created automatically. Owned vehicles are read from your framework's vehicle table.

### Permissions

No ACE permissions are required. Master access is granted by job via `Config.Keys.masterJobs`.

## Configuration

Editable files: `config/keys.lua`, `config/ui.lua` (look, language), `locales/de.json`, `locales/en.json`, and the framework bridge in `shared/` (`cc_framework.lua`, `cc_vehicles.lua`, `cc_vehicleprops.lua`). Set `locale = 'en'` in `config/ui.lua` for English.

### Keys and feedback

```lua
Config.Debug = false

Config.Keys = {
    key = 'L',          -- lock/unlock
    engineKey = 'U',    -- engine on/off
    menuKey = 'F3',     -- open key ring
    distance = 8.0,     -- range for locking
    signal = {
        lights = true,  -- indicator flash
        fob = true,     -- key fob sound from the vehicle
        horn = false,
        doors = true,   -- door sound when locking
    },
    requireKeysToDrive = true, -- engine cannot be started without a key
```

{% hint style="info" %}
The keys are registered with `RegisterKeyMapping`. After the first join, players change them in the FiveM key bindings; changing the config only affects players who have not bound them yet.
{% endhint %}

### Lending

```lua
    lendMinutes = 30,   -- lending duration, 0 = unlimited
    lendDistance = 5.0, -- max distance when handing over a key
    maxBorrowers = 3,   -- borrowers per vehicle
    lendOnward = false, -- borrowers may not lend keys on
    masterJobs = { 'police', 'mechanic' }, -- jobs that can open every vehicle
}
```

{% hint style="warning" %}
`lendOnward = false` is part of the anti-dupe protection. Only change it if you know why.
{% endhint %}

### Images

```lua
Config.Images = {
    enabled = true,
    base = 'https://cfx-nui-cc_images/vehicles',
    extension = 'webp',
}
```

## Exports, Events & Commands

### Server exports

| Export                           | Returns   | Description                                                                       |
| -------------------------------- | --------- | --------------------------------------------------------------------------------- |
| `HasKeys(src, plate)`            | `boolean` | Whether the player has a key for the plate                                        |
| `GiveKeys(src, plate, options?)` | `boolean` | Give a key. `options` = minutes, or `{ minutes, kind, from, label, model, hash }` |
| `RemoveKeys(src, plate)`         | `boolean` | Remove the player's key for the plate                                             |
| `RevokeAll(plate)`               | -         | Revoke every key for the plate (use on sale/transfer)                             |

`kind` is `owner`, `borrowed` or `temporary`. Without `kind`, a key with minutes greater than 0 is temporary, otherwise owned.

```lua
exports.cc_keys:GiveKeys(src, plate, 15)     -- temporary key for 15 minutes
exports.cc_keys:RevokeAll(plate)
```

### Client exports

| Export           | Returns   |
| ---------------- | --------- |
| `HasKeys(plate)` | `boolean` |

### Events listened to

| Event                 | Side   | Arguments            | Effect                              |
| --------------------- | ------ | -------------------- | ----------------------------------- |
| `cc:characterDeleted` | Server | `identifier, plates` | Removes keys of a deleted character |

### Commands

| Command          | Default key | Effect                                             | Permission            |
| ---------------- | ----------- | -------------------------------------------------- | --------------------- |
| `cc_lock`        | L           | Lock/unlock the nearest vehicle you have a key for | Everyone              |
| `cc_motor`       | U           | Engine on/off (driver seat, with key)              | Everyone              |
| `/keys`          | F3          | Open the key ring                                  | Everyone              |
| `/givekeys [ID]` | -           | Give the key of your current vehicle               | Everyone (owner only) |

Plates are compared in upper case without spaces.

## FAQ & Troubleshooting

**Lent keys are gone after a restart.** Borrowed and temporary keys are kept in memory and are lost on a server or resource restart. Owned keys are reloaded from the vehicle table.

**I can't start the engine.** With `requireKeysToDrive = true` you need a key and must sit in the driver seat. Press U (`cc_motor`).

**I can't lend my key.** Only the registered owner can lend. Check `lendDistance` (the other player must be close), `maxBorrowers` and that you are not a borrower yourself (`lendOnward = false`).

**Changing `key` in the config does nothing.** Key bindings are stored per player by FiveM. Players change them in the FiveM settings under key bindings.

**Other scripts give no keys.** Make sure cc\_keys is started before those scripts in `server.cfg`.

**The key ring shows no location for my vehicle.** Keys never spawn vehicles. Positions come from cc\_garage/00%20Overview\.md); without a garage there is no position display.

**Police or mechanics should open every car.** Add their jobs to `Config.Keys.masterJobs`.

Still stuck? See Support.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ccfivem.gitbook.io/ccfivem-docs/vehicles/vehicle-keys-cc_keys.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
