# T1GER Keys

<img src="https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-Mkrx0dMrELmfhy1g76Y%2F-MkrxNe-tgYldgpnJKhY%2FKEYS_COVER.png?alt=media&#x26;token=62d43a9a-08a8-4613-bc27-972107b6352a" 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](https://docs.t1ger.net/free-resources/broken-reference) for instructions).
3. Install and ensure [dependencies](https://docs.t1ger.net/free-resources/broken-reference) for the resource.
4. Setup`config.lua` (⚠️see [#CONFIGURATION](https://docs.t1ger.net/free-resources/broken-reference) 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](https://docs.t1ger.net/free-resources/broken-reference) 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.](https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-Mks4AjmPGZ0IARhUxfH%2F-MksD5RUpqNNMKDPHLQS%2F16d79927f87f441a0cacfe01725d0362%20\(1\).png?alt=media\&token=a399369d-176f-43c3-a474-bdcf3feecf37)

## 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)](https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-MkrmKjpN23xnlgjggI0%2F-MkrnToeBboLXRVFRL4A%2F58e896cbb8f4f89f126d8959e9169a5a.png?alt=media\&token=3f1c14d1-c352-430f-9f55-a38ac04bbddb)
{% 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)](https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-MkroFJruJZuXS2ni11-%2F-MkrorXLejcCpKZYw2Ko%2F72bfa49c3310faa83c6a2f5525f8b50f.png?alt=media\&token=dfe19f86-dd86-4d70-b68b-b807f8f060bf)
{% 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)](https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-Mkrp2BMh5NX8hfNxbH5%2F-MkrqH0OiQ2WQz3JVWk0%2F6761a66d2c59b2c77292d5fe5d868104.png?alt=media\&token=0d3cbdd7-df69-436b-87c1-509a7679a89e)
{% 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)](https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-MkrqzyS7ya0FBiZtKq4%2F-Mkrs700G9nFsRpLML7t%2Fe33353d5fc0f85aaa347fb5e8aead497.png?alt=media\&token=c7372b79-688d-47e5-9684-1a03fc2d9b3f)

### 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](https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiDWIMbFBeXle-trOlk%2F-Mkrtt_HNHYpGfsZ2Lw4%2F-Mkrv1zvFjD8p1z9td-O%2FupdateVehicleKeys.png?alt=media\&token=2a9a5417-39cf-4d6d-b17e-be1ce4adfa23)
{% 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](https://docs.t1ger.net/free-resources/broken-reference).                                                     |
| `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](https://docs.t1ger.net/free-resources/broken-reference).&#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](https://docs.t1ger.net/free-resources/broken-reference).&#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 %}
