> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thunder-studio.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Vehicle Keys Bridges

> Lock and unlock vehicles with one simple bridge.

Vehicle keys bridges abstract how different key systems lock and unlock vehicles.\
Your scripts call one function, and TS-Lib routes it to `qb-vehiclekeys`, `qs-vehiclekeys` or a standalone implementation.

```lua theme={null}
-- Shared
Bridge.VehicleKeys
Bridge.VehicleKeys.Client
Bridge.VehicleKeys.Server
```

***

## Status & testing

| Keys system      |    Status    |            Tested by |
| :--------------- | :----------: | -------------------: |
| `qb-vehiclekeys` |  **Tested**  |      Thunder Scripts |
| `qs-vehiclekeys` | Experimental | waiting for feedback |
| `lfKeys`         |  **Tested**  |      Thunder Scripts |
| `standalone`     |  **Tested**  |      Thunder Scripts |

***

## Supported key systems

TS-Lib ships with support for:

* `qb-vehiclekeys`
* `qs-vehiclekeys`
* `lfKeys`
* `standalone` (no external keys resource)

Configuration is controlled via `ts-lib/config.lua`:

```lua theme={null}
Config.VehicleKeys = 'auto' -- 'auto', 'qb-vehiclekeys', 'qs-vehiclekeys', 'lfKeys', 'standalone'

Config.Data = {
  VehicleKeys = {
    ['qb-vehiclekeys'] = 'qb-vehiclekeys',
    ['qs-vehiclekeys'] = 'qs-vehiclekeys',
    ['lfKeys']         = 'lfKeys',
    ['standalone']     = 'standalone',
  },
}
```

When `Config.VehicleKeys = 'auto'`, TS-Lib selects the first started resource from `Config.Data.VehicleKeys`.

***

## Client-side API

### `Bridge.VehicleKeys.Client.Functions.SetDoorStatus(entity, lockStatus)`

This is the main entrypoint you will use from your scripts.

```lua theme={null}
Bridge.VehicleKeys.Client.Functions.SetDoorStatus(vehicle, 2) -- lock
Bridge.VehicleKeys.Client.Functions.SetDoorStatus(vehicle, 1) -- unlock
```

**Lock status convention** (GTA natives):

* `1` – unlocked
* `2` – locked
* `4` – locked for all players, etc.

#### Behavior per system

* **`qb-vehiclekeys`**

  ```lua theme={null}
  Bridge.VehicleKeys.Client.Functions.SetDoorStatus = function(entity, status)
      TriggerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(entity), status)
  end
  ```

* **`qs-vehiclekeys`**

  ```lua theme={null}
  Bridge.VehicleKeys.Client.Functions.SetDoorStatus = function(entity, status)
      exports["qs-vehiclekeys"]:DoorLogic(entity, true, status, true, true, true)
  end
  ```

* **`lfKeys`**

  ```lua theme={null}
  Bridge.VehicleKeys.Client.Functions.SetDoorStatus = function(entity, status)
      local netId = NetworkGetNetworkIdFromEntity(entity)
      if not netId then return end

      local isLocking = status ~= 0 and status ~= 1
      TriggerServerEvent('vehicle:syncLock', netId, status, isLocking)
  end
  ```

* **`standalone`**

  ```lua theme={null}
  Bridge.VehicleKeys.Client.Functions.SetDoorStatus = function(entity, lockStatus)
      local isLocked = (lockStatus ~= 1 and lockStatus ~= 0)
      Entity(entity).state:set('isLocked', isLocked, true)
      SetVehicleDoorsLocked(entity, lockStatus)

      if lockStatus == 2 or lockStatus == 4 then
          SetVehicleDoorsLockedForAllPlayers(entity, true)
      else
          SetVehicleDoorsLockedForAllPlayers(entity, false)
      end
  end
  ```

In standalone mode, lock state is kept entirely via entity state and natives, without any external resource.

***

## Server-side API

Right now TS-Lib does not expose additional server-side helpers for keys.\
The server bridge (`Bridge.VehicleKeys.Server`) is kept as a placeholder for future extensions:

* Centralized key granting/revoking
* Permission-aware lock/unlock operations
* Auditing of lock events

You are free to extend it in your own fork following the same structure as the existing bridges.

***
