# Exports

{% tabs %}
{% tab title="Client Exports" %}
Vehicle entity id is passed to all of these exports. Here are a few examples of how to determine the vehicle entity in your function or event.

<div align="left" data-full-width="true"><figure><img src="https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2F0ttzkrH3qCXyaSdFu3Uk%2Faddkey__client_final.png?alt=media&#x26;token=358a33bc-d595-43ad-a5a1-857635f85f5a" alt=""><figcaption></figcaption></figure></div>

**`AddKey`** - Give the player keys to the specified vehicle

```lua
exports["mk_vehiclekeys"]:AddKey(vehicle)
```

**`HasKey`** - Check if the player has keys to the specified vehicle

```lua
--Returns true or false
exports["mk_vehiclekeys"]:HasKey(vehicle)

--Example
if exports["mk_vehiclekeys"]:HasKey(vehicle) then 
    print('player has keys')
else
    print('player does not have keys')
end
```

**`HasFlyingAuth`** - Check if the player is authorized to fly the specified vehicle. Only call this export on vehicles that are designated helicopters or planes (Vehicle class 15 or 16)

<pre class="language-lua"><code class="lang-lua"><strong>--Returns true or false
</strong><strong>exports["mk_vehiclekeys"]:HasFlyingAuth(vehicle)
</strong><strong>
</strong><strong>--Example
</strong><strong>if GetVehicleClass(vehicle) == 15 or GetVehicleClass(vehicle) == 16 then --plane or helicopter
</strong><strong>    if exports["mk_vehiclekeys"]:HasFlyingAuth(vehicle) then 
</strong><strong>        print('player can fly this vehicle')
</strong><strong>    else
</strong><strong>        print('player cannot fly this vehicle')
</strong><strong>    end
</strong><strong>else
</strong><strong>    print('not a plane or helicopter')
</strong><strong>end
</strong></code></pre>

**`ToggleLocks`** - Toggle locks of the specified vehicle the player has keys for. Must be within 7.5 distance of the vehicle. Useful for targeting system or radial menu to toggle vehicle locks.

```lua
exports["mk_vehiclekeys"]:ToggleLocks(vehicle)
```

**`UnlockVehicle`** - Unlock a vehicle without requiring keys (useful for police or mechanic type jobs)

```lua
exports["mk_vehiclekeys"]:UnlockVehicle(vehicle)
```

**`ChangeOwner`** - Changes vehicle owner when selling between player. Only call for player owned vehicles. Call export on the player that is being made the new owner. If vehicle is not defined the script will check the closest vehicle to the player.

```lua
--Set player as owner of a specific vehicle
exports["mk_vehiclekeys"]:ChangeOwner(vehicle)

--Set player as owner of the closest vehicle
exports["mk_vehiclekeys"]:ChangeOwner()
```

**`UsingKeyFobs`** - Checks if key fobs are enabled by the script

```lua
--Returns true or false
exports["mk_vehiclekeys"]:UsingKeyfobs()
```

**`RemoveKey`** - Remove keys from a specified player to the specified vehicle

```lua
--This does not apply to keyfobs
exports["mk_vehiclekeys"]:RemoveKey(vehicle)
```

{% endtab %}

{% tab title="Server Exports" %}
Vehicle entity id is passed to most of these exports. Here are a few examples of how to determine the vehicle entity in your function or event.

<div align="left" data-full-width="true"><figure><img src="https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2FMNJ8DAe7HhW4kajRzKPc%2Faddkey_client_1.png?alt=media&#x26;token=946e411a-37b8-4bab-815c-2972254ddf5e" alt=""><figcaption></figcaption></figure></div>

**`AddKey`** - Give the specified player keys to the specified vehicle

```lua
exports["mk_vehiclekeys"]:AddKey(vehicle, source)
```

**`HasKey`** - Check if the specified player has keys to the specified vehicle

```lua
--Returns true or false
exports["mk_vehiclekeys"]:HasKey(vehicle, source)

--Example
if exports["mk_vehiclekeys"]:HasKey(vehicle, source) then 
    print('player has keys')
else
    print('player does not have keys')
end
```

**`ChangeOwner`** - Changes vehicle owner when selling between player. Only call for player owned vehicles. Call export on the player that is being made the new owner.

```lua
exports["mk_vehiclekeys"]:ChangeOwner(vehicle, source)
```

**`UpdatePlate`** - Update mk\_keyfobs database with new plate. Run this export if you use a script that updates vehicle plates in the database (example: vanity plate script). Not doing this will cause issues with your keyfobs. **Does not need to be ran if you are not using Keys as Items**

```lua
exports["mk_vehiclekeys"]:UpdatePlate(oldPlate, newPlate)
```

**`UsingKeyFobs`** - Checks if key fobs are enabled by the script

```lua
--Returns true or false
exports["mk_vehiclekeys"]:UsingKeyfobs()
```

**`RemoveKey`** - Remove keys from a specified player to the specified vehicle

```lua
--This does not apply to keyfobs
exports["mk_vehiclekeys"]:RemoveKey(vehicle, source)
```

{% endtab %}
{% endtabs %}
