# T1GER Keys

<img src="/files/-MkrxNe-tgYldgpnJKhY" alt="" data-size="original">

#### [**View on Tebex**](https://store.t1ger.net/category/1817449) | [**CFX Forum Post**](https://forum.cfx.re/t/esx-t1ger-keys-with-npc-vehicles-lock-locking-unlocking-vehicles-lockpicking-hotwire-search-and-more/4766312/2) | [**YouTube Showcase**](https://youtu.be/FvTIlO4SBBg) | [**Discord**](https://discord.gg/t1ger)

## INSTALLATION

### DEPENDENCIES

|  Dependency  |                                       Download                                       |    Install   | Description                                                    |
| :----------: | :----------------------------------------------------------------------------------: | :----------: | -------------------------------------------------------------- |
| ProgressBars | [Link](https://gitlab.com/t1ger-scripts/t1ger-requirements/-/tree/main/progressBars) | **Optional** | If not using, set`Config.ProgressBars` to false in`config.lua` |

### START

1. Extract`t1ger_keys.rar` and place it into your resource folder.
2. Install the SQL file into your database (⚠️see [#SQL](broken://pages/-MkqCKKqi2Y1_UwFU3DB#sql) for instructions).
3. Install and ensure [dependencies](broken://pages/-MkqCKKqi2Y1_UwFU3DB#dependencies) for the resource.
4. Setup`config.lua` (⚠️see [#CONFIGURATION](broken://pages/-MkqCKKqi2Y1_UwFU3DB#configuration) for instructions).&#x20;
5. Add`ensure t1ger_keys`to your server start config (place it anywhere below the dependency & framework resources).
6. Update the SetVehicleDoorsLocked() native in all your resources to use my export function instead (see [instructions](broken://pages/-MkqCKKqi2Y1_UwFU3DB#vehicle-locked-status) here)

### SQL

{% hint style="danger" %}
Please note, there are **two** SQL files, you only need to use one of them, depending on whether you had my old`t1ger_keys` resource installed or not.\
\
If you already have`gotKey` and`alarm` columns in your`owned_vehicles` table in database, then use`t1ger_keys_update.sql` file.\
Otherwise, you can use the`t1ger_keys_add.sql`file.\
\
You can open the respective SQL file, copy the queries and execute/run them in your database manually (my personal preferred way) or you can import the file.
{% endhint %}

### CONFIGURATION

{% hint style="warning" %}
Please go through **all** configurable options & settings in `config.lua` and configure them to your server's preferences.

Also please read the comments at the end of each line, for a brief information on what the option does.&#x20;
{% endhint %}

### UTILITIES

{% hint style="info" %}
In`client/utils.lua` there is a file where you can edit some utility functions. In here you can customize notifications, draw texts and many other functions. \
Please do read it through and make changes to meet your server's preferences.
{% endhint %}

### VEHICLE LOCKED STATUS

You need to replace the`SetVehicleDoorsLocked()` native with my export function below. This is because my resource uses decors which syncs much better and when using the native to lock/unlock a vehicle, the decors of the vehicle aren't updated, meaning you'd face syncing issues.&#x20;

```lua
exports['t1ger_keys']:SetVehicleLocked(vehicle, int)
-- vehicle is the vehicle entity that you want to execute the function on.
-- int is the lock door status interger (0 or 1 is unlocked, 2 or 10 is locked)
-- (see more here: https://docs.fivem.net/natives/?_0xB664292EAECF7FA6)
```

Best and easiest way to replace, is simply search for`SetVehicleDoorsLocked(` in your files and replace with my export function. **Reminder;** make sure to set the correct variables for vehicle and int, they have to be the exact same as you had in the native you replaced/about to replace.

{% hint style="warning" %}
If you **don't** want vehicles locked by default when spawned, then manually add the export function and set the`int` to either`0` or`1`.&#x20;
{% endhint %}

I have added the export inside my`ESX.Game.SpawnVehicle()` function, so all my resources using this function, will automatically set vehicles to be unlocked. For resources not using that function, you'd need to add the export in manually in the script.&#x20;

![Example of adding unlocked state to vehicle spawned using ESX.Game.SpawnVehicle function.](/files/-MksD5RUpqNNMKDPHLQS)

## ADDING KEYS

Follow these instructions to add keys for player or jobs for a vehicle.&#x20;

### JOB KEYS

To add job keys for a vehicle used for a job, use this export function in your client-sided files:

```lua
exports['t1ger_keys']:GiveJobKeys(plate, name, boolean, jobs)
-- plate; is the plate variable of the vehicle 
-- name; is the vehicle display name, using GetLabelText() and GetDisplayNameFromVehicleModel()
-- boolean; is true/false, where true add keys to the player, false doesnt add keys to the player
-- jobs; is a table of jobs, that should have lock/unlock access to the vehicle
```

{% hint style="warning" %}
***CLICK THE TABS TO SEE OPTIONS***
{% endhint %}

{% tabs %}
{% tab title="Keys for player" %}
This example shows how to add job keys for a player and **not** allowing any jobs to have access to the vehicle.

```lua
exports['t1ger_keys']:GiveJobKeys(plate, name, true)
-- plate is the vehicle plate
-- name is the vehicle display name
-- source player keeps the keys
-- last variable is indifferent, as its not for any jobs.
```

![Example of adding job keys to a player and not allowing any jobs (code is from T1GER Garage)](/files/-MkrnToeBboLXRVFRL4A)
{% endtab %}

{% tab title="Keys for jobs" %}
This example shows how to add job keys for a job or multiple jobs and auto-removes access to the spawned vehicle from players that switches job or goes off-duty.

```lua
exports['t1ger_keys']:GiveJobKeys(plate, name, false, {'police','lspd'})
-- plate is the vehicle plate
-- name is the vehicle display name
-- source player loses keys if switching jobs.
-- all players with job 'police' or 'lspd' has access to the vehicle.
```

![Example of adding job keys to a job/multiple jobs (code is from T1GER Garage)](/files/-MkrorXLejcCpKZYw2Ko)
{% endtab %}

{% tab title="Keys for player + jobs" %}
This example shows how to add job keys for jobs and allowing source player to keep the keys, in case he switches jobs or goes off-duty.

```lua
exports['t1ger_keys']:GiveJobKeys(plate, name, true, {'police'})
-- plate is the vehicle plate
-- name is the vehicle display name
-- true means source player keeps the if he goes off-duty or switch job
-- all players with job 'police' have access to the vehicle.
```

![Example of adding job keys to a job and letting source player keep the keys (code is from T1GER Garage)](/files/-MkrqH0OiQ2WQz3JVWk0)
{% endtab %}
{% endtabs %}

### TEMPORARY KEYS

To add temporary keys to a vehicle for player, you need to use this export function in your client-sided files. &#x20;

```lua
exports['t1ger_keys']:GiveTemporaryKeys(plate, name, type)
-- plate; is the plate variable of the vehicle 
-- name; is the vehicle display name, using GetLabelText() and GetDisplayNameFromVehicleModel()
-- type; is the label shown in keys menu, after the plate.
-- I for example use: 'stolen' -for keys gotten from NPCs at gunpoint aim
```

![Example of adding temporary keys (code snippet from T1GER Keys)](/files/-Mkrs700G9nFsRpLML7t)

### OWNED KEYS

{% hint style="danger" %}
***VEHICLE MUST EXIST IN DATABASE, ONLY AFTER THE FUNCTION OR TRIGGERSERVEREVENT MUST BE USED.***&#x20;
{% endhint %}

To add keys for owned vehicle, which are permanent, it requires the vehicle to be registered in`owned_vehicles` table in the database (of course, otherwise it wouldn't be an owned vehicle).&#x20;

{% hint style="warning" %}
***CLICK THE TABS TO SEE OPTIONS***
{% endhint %}

{% tabs %}
{% tab title="Server-side" %}
Use this export function to add keys from a server-sided environment:

```lua
exports['t1ger_keys']:UpdateKeysToDatabase(plate, state)
-- plate; plate of the vehicle in database that needs its keys state updated.
-- state; set it to true/false, where true means adding keys, false means removing keys.
-- example: https://ibb.co/vDx6czs
```

![Example of adding the export function to add keys after the purchase in T1GER Cardealer](/files/-Mkrv1zvFjD8p1z9td-O)
{% endtab %}

{% tab title="Client-side" %}
Use this trigger event to add keys from a client-sided environment:

```lua
TriggerServerEvent('t1ger_keys:updateOwnedKeys', plate, state)
-- plate; plate of the vehicle in database that needs its keys state updated.
-- state; set it to true/false, where true means adding keys, false means removing keys.
```

{% hint style="danger" %}
***When triggering this event from client-sided environments, you really need to make sure that the vehicle is existing in database!***
{% endhint %}
{% endtab %}
{% endtabs %}

## MISCELLANEOUS

### CHAT COMMANDS

{% hint style="info" %}
*Please note, all these command strings are configurable and can be disabled as well.*
{% endhint %}

| Command     | Description                                                            |
| ----------- | ---------------------------------------------------------------------- |
| `/lock`     | Locks or unlocks the closest vehicle or the vehicle player is in.      |
| `/keys`     | Opens menu showing all current keys a player has.                      |
| `/carmenu`  | Opens the car interaction menu (doors, windows, engine, neon and keys) |
| `/engine`   | Toggles engine on/off depending on its running state.                  |
| `/lockpick` | Triggers the lockpick event/function                                   |
| `/search`   | Search the car for loot if possible.                                   |
| `/hotwire`  | Hotwire vehicle to turn on the engine                                  |

### EXPORTS

{% hint style="info" %}
These are available exports in the resource - use them as you please and find necessary.
{% endhint %}

| Export Function                                               | Description                                                                                                                                                                                                                        |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `exports['t1ger_keys']:SetVehicleLocked(vehicle, int)`        | Sets the vehicle locked status using decors and handles the door lock sync properly for the vehicle. More info [here](broken://pages/-MkqCKKqi2Y1_UwFU3DB#vehicle-locked-status).                                                  |
| `exports['t1ger_keys']:GetVehicleLockedStatus(vehicle)`       | Returns the locked status integer for a given vehicle. Use this function to check if vehicle is locked. Replace this  [native](https://docs.fivem.net/natives/?_0xD72CEF2) with the export function, to get better synced results. |
| `exports['t1ger_keys']:SetVehicleCanSearch(vehicle, boolean)` | By default vehicles cannot be searched (unless its enabled for different events in config). Use this export on a given vehicle to allow searching it once. Boolean must be`true` .                                                 |
| `exports['t1ger_keys']:SetVehicleHotwire(vehicle, boolean)`   | By default vehicles does not require hotwiring (unless its enabled for different events in config). Use this export on a given vehicle to require a hotwiring to start the engine. Boolean must be`true`.                          |
| `exports['t1ger_keys']:ToggleVehicleEngine(vehicle)`          | Toggle vehicle engine, depending on its running state. The vehicle variable is not necessary to be sent, function will check for the vehicle player is in.                                                                         |

## SCRIPT NOT WORKING / ERRORS

{% hint style="success" %}
**VEHICLE NAME NULL**\
[❓](https://emojipedia.org/question-mark/)  My vehicles show up as NULL and not by name.

[✔️](https://emojiguide.com/symbols/check-mark/) Please read [this post](https://forum.cfx.re/t/how-to-add-on-vehicles-detailed/37501) on CFX Forum on how to properly add custom vehicles to your server. If that didn't fix your issue, then find the respective`vehicles.meta` file (typically located in your stream folder for the given vehicle). In here you want to set the`<gameName>` property to match the given vehicle mode in your`vehicles` table in database. There is a [youtube guide here](https://youtu.be/m5mR9qUy164), I don't understand the language but the video itself should give you an idea.
{% endhint %}

{% hint style="success" %}
**SPAWNED VEHICLES ARE LOCKED**\
[❓](https://emojipedia.org/question-mark/)  I spawn a vehicle, exit the vehicle, try to enter it but it's locked.&#x20;

[✔️](https://emojiguide.com/symbols/check-mark/) Please see this part of the documentation, for instructions on how to locked status of spawned vehicles: [click here](broken://pages/-MkqCKKqi2Y1_UwFU3DB#vehicle-locked-status).&#x20;
{% endhint %}

{% hint style="success" %}
**TRUNK / GLOVEBOX**\
[❓](https://emojipedia.org/question-mark/)  I cannot access my trunk/glovebox; it says vehicle is locked.

[✔️](https://emojiguide.com/symbols/check-mark/) You need to update your relevant resources to use my export function for getting the vehicle locked status:

`exports['t1ger_keys']:GetVehicleLockedStatus(vehicle)`
{% endhint %}

{% hint style="success" %}
**TEMPORARY/JOB KEYS NOT WORKING**\
[❓](https://emojipedia.org/question-mark/)  Added temporary or job keys for a given vehicle does not work. I can not lock/unlock.

[✔️](https://emojiguide.com/symbols/check-mark/) Please see this part of the documentation, for instructions on how to properly add job or temporary keys: [click here](broken://pages/-MkqCKKqi2Y1_UwFU3DB#adding-keys).&#x20;
{% endhint %}

{% hint style="info" %}
[🆘](https://emojipedia.org/sos-button/) **IF YOU HAVE TRIED YOUR BEST AND NOTHING WORKS, THEN CONTACT US ON OUR OFFICIAL DISCORD:** [**CLICK HERE**](https://discord.gg/FdHkq5q)**.**
{% endhint %}


---

# 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://docs.t1ger.net/free-resources/t1ger-keys.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.
