# Keys as Items

Enable this feature in `config.lua`

<div align="left"><figure><img src="https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2Fflv24qGvGgLmMmiab05w%2Fkeyfob_enable.png?alt=media&#x26;token=160ccb22-3bb3-439d-8a56-976f95bf6063" alt=""><figcaption></figcaption></figure></div>

Run Keyfobs.sql or the following query into your database

```sql
CREATE TABLE IF NOT EXISTS `mk_keyfobs` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`owner` VARCHAR(50) NULL DEFAULT NULL,
	`plate` VARCHAR(50) NULL DEFAULT NULL,
	`fakeplate` VARCHAR(50) NULL DEFAULT NULL,
	`model` VARCHAR(50) NULL DEFAULT NULL,
	`fobid` VARCHAR(50) NULL DEFAULT NULL,
	`old_fobs` LONGTEXT NULL DEFAULT NULL,
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `owner` (`owner`) USING BTREE,
	INDEX `plate` (`plate`) USING BTREE,
	INDEX `fobnumber` (`fobid`) USING BTREE,
	INDEX `Column 6` (`old_fobs`(1024)) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

```

**Framework Setup**

{% tabs %}
{% tab title="QBCORE" %}
Add `carkey` item to `qb-core/shared/items.lua`&#x20;

{% code fullWidth="false" %}

```lua
['carkey'] 				 		 = {['name'] = 'carkey', 			  	  		['label'] = 'Vehicle Keys', 			['weight'] = 100, 		['type'] = 'item', 		['image'] = 'carkey.png', 				['unique'] = true, 		['useable'] = true, 	['shouldClose'] = true,   ['combinable'] = nil,   	['description'] = 'Vehicle Key Fob'},
```

{% endcode %}

{% endtab %}

{% tab title="QBX" %}
No additional framework setup needed
{% endtab %}

{% tab title="ESX" %}
No additional framework setup needed
{% endtab %}

{% tab title="Custom Framework" %}
No additional framework setup needed
{% endtab %}
{% endtabs %}

**Inventory Setup**

{% tabs %}
{% tab title="qb-inventory (classic)" %}
Add `carkey` item metadata

* Open file `qb-inventory/html/js/app.js`&#x20;
* Locate function `FormatItemInfo(itemData)`&#x20;
* Insert the following else if statement

{% code fullWidth="false" %}

```javascript
else if (itemData.name == "carkey") {
    $(".item-info-title").html('<p>'+itemData.label+'</p>')
    $(".item-info-description").html("<p><strong>Brand: </strong>" + itemData.info.brand + "</p><p><strong>Name: </strong>" + itemData.info.name + "</p><p><strong>Vehicle ID: </strong>" + itemData.info.id + "</p><p><strong>Plate: </strong>" + itemData.info.plate + "</p>");
}
```

{% endcode %}

Example of finished insert:

<figure><img src="https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2F0QaJougOViOcoh5JekS7%2Fkeys_fob_qb_metadata.png?alt=media&#x26;token=79f3d111-3a1f-4256-bd63-17c90e97fa86" alt=""><figcaption></figcaption></figure>

Add `carkey` image

* add the following image (or your own) to `qb-inventory/html/images/`&#x20;
* ![](https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2FYAqySKS3Efnobyz5PCw3%2Fcarkey.png?alt=media\&token=f85b56e5-d333-435c-b12d-48dc1e2dc10d)
  {% endtab %}

{% tab title="qb-inventory (v1.2.4+)" %}
Add `carkey` item metadata

* Open file `qb-inventory/html/js/app.js`&#x20;
* Locate function `generateDescription`&#x20;
* Insert the following case

```javascript
case "carkey":
            return `<p><strong>Brand: </strong>${itemData.info.brand}</p>
            <p><strong>Name: </strong>${itemData.info.name}</p>
            <p><strong>Vehicle ID: </strong>${itemData.info.id}</p>
            <p><strong>Plate: </strong>${itemData.info.plate}</p>`;
```

Example of finished insert:

<figure><img src="https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2FZvvDXCDIuofUZ2ViHbnD%2Fkeys_fob_qb_meta_new.png?alt=media&#x26;token=b9606175-ebad-4ca4-acfd-09208a2206e5" alt=""><figcaption></figcaption></figure>

* Add `carkey` image
* add the following image (or your own) to `qb-inventory/html/images/`&#x20;
*

```
<div align="left"><figure><img src="https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2FYAqySKS3Efnobyz5PCw3%2Fcarkey.png?alt=media&#x26;token=f85b56e5-d333-435c-b12d-48dc1e2dc10d" alt=""><figcaption></figcaption></figure></div>
```

{% endtab %}

{% tab title="ox\_inventory" %}
Add the following item into `ox_inventory/data/items.lua`&#x20;

```lua
['carkey'] = {
    label = 'Vehicle Keys',
    weight = 1,
    consume = 0,
    stack = false,
    close = true,
    server = {
        export = 'mk_vehiclekeys.usevehkey'
    },
},
```

add the following image (or your own) to `ox_inventory/web/images/`&#x20;

![](https://51694285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSadY5GIZVZCGCeog04Gq%2Fuploads%2FYAqySKS3Efnobyz5PCw3%2Fcarkey.png?alt=media\&token=f85b56e5-d333-435c-b12d-48dc1e2dc10d)
{% endtab %}

{% tab title="other" %}

* Custom inventory must support item metadata to use this feature
* Setup item based upon your inventory
  * Key item metadata \<key, value>
    * name = vehicle name
    * id = keyfob id (tracked in database)
    * plate = vehicle plate text
* Setup custom inventory in `[mk_utils]` bridge files
  {% endtab %}
  {% endtabs %}
