# Fix hotwiring bought car

## Generic script

If after you purchase a vehicle you have to hotwire it, you only have to add [this simple line of code ](https://documentation.jaksam-scripts.com/vehicles-keys/client/refresh-self-owned-vehicles)in your script code, after you know that the vehicle is added in `owned_vehicles` / `player_vehicles` table (depending on the framework)

You may want to add a `Citizen.Wait(2000)` before that line in case the vehicle wasn't yet in the table in the moment you triggered the event

## esx\_vehicleshop

### First step

Go to `esx_vehicleshop/server/main.lua` and search for the following code:

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-5035a5d13e472af53da8b7418989a88506ae9f4c%2Fesx_vehicleshop_setVehicleOwnedPlayerId_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add this line

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(playerId)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-886ea8f756f91640c725985f04a3e48f57fed2db%2Fesx_vehicleshop_setVehicleOwnedPlayerId_after.png?alt=media" alt=""><figcaption></figcaption></figure>

### Second step

Go to `esx_vehicleshop/server/main.lua` (the same file as before) and search for the following code:

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-482f70c85ca793b5e8f29cc9adf9d46711c381fa%2Fesx_vehicleshop_buyVehicle_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add this line

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(source)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-f61a04c665c9cd690cec334333e8f4dbba7afa1c%2Fesx_vehicleshop_buyVehicle_after.png?alt=media" alt=""><figcaption></figcaption></figure>

## esx\_advancedvehicleshop

Go to `esx_advancedvehicleshop/server/main.lua` and search for the following code:

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-2e18cb67ed7a93c667867e744502793215f3090c%2Fesx_advancedvehicleshop_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add this line

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(source)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-57b07d2885ac2c7ee32e94187009467d4c0c15ed%2Fesx_advancedvehicleshop_after.png?alt=media" alt=""><figcaption></figcaption></figure>

## qb-vehicleshop

### First step

Go to `qb-vehicleshop/server.lua` and you will have to add the following code after **all** `exports.oxmysql:insert`

In the example, it will be shown only one time, but you have to add it multiple times

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-29d32c3789f36d68a6e6f00ae66b3ea83cd78fb3%2Fqb-vehicleshop_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add the following code

```lua
SetTimeout(1000, function() 
    exports["vehicles_keys"]:refreshPlayerOwnedVehicles( pData.PlayerData.source )
end)
```

In certain parts, you will have to replace `pData` with something else, here it will show where to add the code and on what `pData` depends

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-41059c186184005a1c065003405f0543eda6ccde%2Fqb-vehicleshop_after.png?alt=media" alt=""><figcaption></figcaption></figure>

**Note**: the green circles showed in the screenshot must match, so if the first one is for example `targetPlayer`, the second one must be `targetPlayer` as well

### Second step

Go to `qb-vehicleshop/server.lua` (the same file as before) and replace all these events (they are at the bottom of the file)

```lua
TriggerClientEvent('vehiclekeys:client:SetOwner', buyerId, plate)
```

with the following code

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(buyerId)
```

## okokVehicleShop

Go to `okokVehicleShop/sv_utils.lua` and search for the following code:

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-332bd1516602f02e8b137b9c62a347f91dd2a64f%2FokokVehicleShop_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add this line

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(_source)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-1f503b3d3a07f923fc2c7e23842f17dc97ce2ede%2FokokVehicleShop_after.png?alt=media" alt=""><figcaption></figcaption></figure>

## s4-vehicleshop

Go to `s4-vehicleshop/server.lua` and search for the following code:

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-89c577dbbc7b07d97f1368f2255823ff8ef5ef03%2Fs4-vehicleshop_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add the following code:

```lua
SetTimeout(1000, function() 
    exports["vehicles_keys"]:refreshPlayerOwnedVehicles(src)
end)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-51e107f17bb4e54a98720293796a727c5df1edea%2Fs4-vehicleshop_after.png?alt=media" alt=""><figcaption></figcaption></figure>

**Note:** this code will work for both *oxmysql* and *ghmattimysql* versions

## t1ger\_dealerships

### First step

Go to `t1ger_dealerships/server/main.lua` and add the following line below **all codes** (more than one) like as shown in the example

```lua
exports['t1ger_keys']:UpdateKeysToDatabase(props.plate, true)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-7369d3eadc7bccb19a22595ece367e4f580a63ac%2Ft1ger_dealerships_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add the following line

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(xPlayer.source)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-5fd25710f7807637c72d1f6789b5ed73e42d1a54%2Ft1ger_dealerships_after.png?alt=media" alt=""><figcaption></figcaption></figure>

### Second step

Go to `t1ger_dealerships/server/main.lua` (same file as before) and search for the following code:

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-60db90dd140f3f60df70170db5dc6b1321c0dccf%2Ft1ger_dealerships2_before.png?alt=media" alt=""><figcaption></figcaption></figure>

And add the following line

```lua
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(xPlayer.source)
```

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-7c07b4fa3773c3e68d15b7ffab0378f170da2375%2Ft1ger_dealerships2_after.png?alt=media" alt=""><figcaption></figcaption></figure>
