# Integrations

{% hint style="danger" %}
You need ***msk\_core***! - [*Download it here*](https://github.com/MSK-Scripts/msk_core)
{% endhint %}

{% hint style="info" %}
This Guide show examples on how to integrate `msk_vehiclekeys` into f.e.: VehicleShops, etc.
{% endhint %}

{% hint style="success" %}
It is already integrated in [MSK EngineToggle](https://forum.cfx.re/t/msk-enginetoggle-toggle-engine-on-off/4793840) and [MSK Garage](https://forum.cfx.re/t/esx-msk-garage-and-impound/5122014)
{% endhint %}

<details>

<summary>EngineToggle Scripts</summary>

* Use [this Export](https://docu.msk-scripts.de/scripts/exports/client#hasplayerkeyorisvehicleowner) on clientside
* Use [this Export](https://docu.msk-scripts.de/scripts/exports/server#hasplayerkeyorisvehicleowner) on serverside

</details>

<details>

<summary>okokVehicleShop</summary>

* Go to `okokVehicleshop\cl_utils.lua` and edit the following Events:

```lua
RegisterNetEvent(Config.EventPrefix..":giveKeys")
AddEventHandler(Config.EventPrefix..":giveKeys", function(vehicle)
    Wait(2000) -- to make sure u are in the vehicle when the key is given
    exports.msk_vehiclekeys:AddPrimaryKey(vehicle)
end)

RegisterNetEvent(Config.EventPrefix..":giveKeysTestDrive")
AddEventHandler(Config.EventPrefix..":giveKeysTestDrive", function(vehicle)
    Wait(2000) -- to make sure u are in the vehicle when the key is given
    exports.msk_vehiclekeys:AddTempKey(vehicle)
end)

RegisterNetEvent(Config.EventPrefix..":giveKeysTowTruck")
AddEventHandler(Config.EventPrefix..":giveKeysTowTruck", function(vehicle)
    Wait(2000) -- to make sure u are in the vehicle when the key is given
    exports.msk_vehiclekeys:AddTempKey(vehicle)
end)

RegisterNetEvent(Config.EventPrefix..":onFinishTestDrive")
AddEventHandler(Config.EventPrefix..":onFinishTestDrive", function(vehicle)
    exports.msk_vehiclekeys:RemoveTempKey(vehicle)
end)

RegisterNetEvent(Config.EventPrefix..":deleteVehicle")
AddEventHandler(Config.EventPrefix..":deleteVehicle", function()
    if sellingVehicle ~= nil then
	exports.msk_vehiclekeys:RemovePrimaryKey(sellingVehicle)
	DeleteEntity(sellingVehicle)
	sellingVehicle = nil
    end
end)
```

</details>

<details>

<summary>dealerships_creator</summary>

* Go to `dealerships_creator/integrations/cl_integrations.lua` and add the following Events:

```lua
AddEventHandler("dealerships_creator:testDrive:vehicleSpawned", function(vehicle, vehicleNetId)
    SetVehicleFuelLevel(vehicle, 100.0)
    exports.msk_vehiclekeys:AddTempKey(vehicle)
end)
```

* Go to `dealerships_creator/integrations/sv_integrations.lua` and add the following Events:

```lua
AddEventHandler("dealerships_creator:giveVehicleToPlayerId", function(playerId, vehicleName, plate)
    Wait(2000) -- To make sure the vehicle is saved in databasse
    exports.msk_vehiclekeys:AddPrimaryKey({source = playerId}, {plate = plate})
end)
```

</details>

<details>

<summary>jobs_creator</summary>

* Go to `jobs_creator/integrations/cl_integrations.lua` and add the following Events:

```lua
AddEventHandler("jobs_creator:permanent_garage:vehicleSpawned", function(vehicle, vehicleName, vehiclePlate)
    Wait(2000) -- to make sure u are in the vehicle when the key is given
    exports.msk_vehiclekeys:AddPrimaryKey(vehicle)
end)

AddEventHandler("jobs_creator:permanent_garage:vehicleParked", function(vehicleModel, vehiclePlate)
    exports.msk_vehiclekeys:RemovePrimaryKey({plate = vehiclePlate, model = vehicleModel})
end)

AddEventHandler("jobs_creator:garage_owned:vehicleSpawned", function(vehicle, vehicleName, vehiclePlate)
    Wait(2000) -- to make sure u are in the vehicle when the key is given
    exports.msk_vehiclekeys:AddPrimaryKey(vehicle)
end)

AddEventHandler("jobs_creator:garage_owned:vehicleParked", function(vehicleModel, vehiclePlate)
    exports.msk_vehiclekeys:RemovePrimaryKey({plate = vehiclePlate, model = vehicleModel})
end)

AddEventHandler("jobs_creator:temporary_garage:vehicleSpawned", function(vehicle, vehicleName, vehiclePlate)
    Wait(2000) -- to make sure u are in the vehicle when the key is given
    exports.msk_vehiclekeys:AddTempKey(vehicle)
end)

AddEventHandler("jobs_creator:temporary_garage:vehicleParked", function(vehicleModel, vehiclePlate)
    exports.msk_vehiclekeys:RemoveTempKey({plate = vehiclePlate, model = vehicleModel})
end)
```

</details>

<details>

<summary>qs-advancedgarages</summary>

* Go to `qs-advancedgarages\config\config.lua` and insert the following on line \~186

```lua
local mskvehiclekeys = GetResourceState('msk_vehiclekeys') == 'started'
```

* Then insert the following at line 208-210

```lua
elseif mskvehiclekeys then
    return 'msk_vehiclekeys'
else
```

* Create a new file named `msk_vehiclekeys.lua` and place this file into: \
  `qs-advancedgarages\client\custom\vehiclekeys`
* Add the following code into this file:

```lua
if Config.Vehiclekeys ~= 'msk_vehiclekeys' then
    return
end

function AddVehiclekeys(vehicle, plate, item)
    exports.msk_vehiclekeys:AddPrimaryKey(vehicle)
end

function RemoveVehiclekeys(vehicle, plate)
    exports.msk_vehiclekeys:RemovePrimaryKey(vehicle)
end
```

</details>
