# Installation

***

## STEP 1 - Download

* Download **mst\_drugdetector** and **mst\_bridge** from [Portal](https://portal.cfx.re/assets/granted-assets).

## STEP 2 - Dependencies

{% hint style="info" %}
The script requires several dependencies to function properly.
{% endhint %}

**Required:**

* [es\_extended](https://github.com/esx-framework/esx_core/tree/main/\[core]/es_extended) or [qb-core](https://github.com/qbcore-framework/qb-core) or [qbx\_core](https://github.com/Qbox-project/qbx_core)
* [mst\_bridge](https://portal.cfx.re/assets/granted-assets)

## STEP 3 - Resource order

{% hint style="info" %}
You MUST start the resource below your core and bridge!
{% endhint %}

<pre data-title="SERVER.CFG"><code>ensure es_extended/qb-core/qbx_core
ensure mst_bridge
<strong>ensure mst_drugdetector
</strong></code></pre>

## STEP 4 - Database

{% hint style="danger" %}
Without adding these items to the database, the script will not work!
{% endhint %}

{% tabs %}
{% tab title="MySQL" %}

```sql
DELETE FROM items WHERE name = 'drugdetector';
DELETE FROM items WHERE name = 'drugdetector_used';
DELETE FROM items WHERE name = 'joint';
DELETE FROM items WHERE name = 'cocaine';
DELETE FROM items WHERE name = 'ecstasy';
DELETE FROM items WHERE name = 'meth';
DELETE FROM items WHERE name = 'heroin';
DELETE FROM items WHERE name = 'morphine';
DELETE FROM items WHERE name = 'xanax';
DELETE FROM items WHERE name = 'narcan';

INSERT INTO `items` (`name`, `label`, `weight`) VALUES
	('drugdetector', 'Drug Detector', 1),
	('drugdetector_used', 'Used Drug Detector', 1),
	('joint', 'Joint', 1),
	('cocaine', 'Cocaine', 1),
	('ecstasy', 'Ecstasy', 1),
	('meth', 'Methamphetamine', 1),
	('heroin', 'Heroin', 1),
	('morphine', 'Morphine', 1),
	('xanax', 'Xanax', 1),
  ('narcan', 'Narcan', 1)
;
```

{% endtab %}

{% tab title="QB" %}

```lua
drugdetector = { name = 'drugdetector', label = 'Drug Detector', weight = 1, type = 'item', image = 'drugdetector.png', unique = false, useable = true, shouldClose = true, description = 'A device used to test for drugs in a person\'s system' },
drugdetector_used = { name = 'drugdetector_used', label = 'Used Drug Detector', weight = 1, type = 'item', image = 'drugdetector_used.png', unique = true, useable = false, shouldClose = true, description = 'A drug detector that has been used and contains test results' },
joint = { name = 'joint', label = 'Joint', weight = 1, type = 'item', image = 'joint.png', unique = false, useable = true, shouldClose = true, description = 'A cannabis joint' },
cocaine = { name = 'cocaine', label = 'Cocaine', weight = 1, type = 'item', image = 'cocaine.png', unique = false, useable = true, shouldClose = true, description = 'Cocaine powder' },
ecstasy = { name = 'ecstasy', label = 'Ecstasy', weight = 1, type = 'item', image = 'ecstasy.png', unique = false, useable = true, shouldClose = true, description = 'Ecstasy pill' },
meth = { name = 'meth', label = 'Methamphetamine', weight = 1, type = 'item', image = 'meth.png', unique = false, useable = true, shouldClose = true, description = 'Methamphetamine crystal' },
heroin = { name = 'heroin', label = 'Heroin', weight = 1, type = 'item', image = 'heroin.png', unique = false, useable = true, shouldClose = true, description = 'Heroin powder' },
morphine = { name = 'morphine', label = 'Morphine', weight = 1, type = 'item', image = 'morphine.png', unique = false, useable = true, shouldClose = true, description = 'Morphine injection' },
xanax = { name = 'xanax', label = 'Xanax', weight = 1, type = 'item', image = 'xanax.png', unique = false, useable = true, shouldClose = true, description = 'Xanax pill' },
narcan = { name = 'narcan', label = 'Narcan', weight = 1, type = 'item', image = 'narcan.png', unique = false, useable = true, shouldClose = true, description = 'Narcan spray' },
```

{% endtab %}

{% tab title="OX" %}

```lua
['drugdetector'] = {
    label = 'Drug Detector',
    weight = 1000,
    stack = true,
    close = true,
    description = 'A device used to test for drugs in a person\'s system',
    client = {
        image = 'drugdetector.png'
    }
},

['drugdetector_used'] = {
    label = 'Used Drug Detector',
    weight = 1000,
    stack = false,
    close = true,
    description = 'A drug detector that has been used and contains test results',
    client = {
        image = 'drugdetector_used.png'
    }
},

['joint'] = {
    label = 'Joint',
    weight = 50,
    stack = true,
    close = true,
    description = 'A cannabis joint',
    client = {
        image = 'joint.png'
    }
},

['cocaine'] = {
    label = 'Cocaine',
    weight = 100,
    stack = true,
    close = true,
    description = 'Cocaine powder',
    client = {
        image = 'cocaine.png'
    }
},

['ecstasy'] = {
    label = 'Ecstasy',
    weight = 50,
    stack = true,
    close = true,
    description = 'Ecstasy pill',
    client = {
        image = 'ecstasy.png'
    }
},

['meth'] = {
    label = 'Methamphetamine',
    weight = 100,
    stack = true,
    close = true,
    description = 'Methamphetamine crystal',
    client = {
        image = 'meth.png'
    }
},

['heroin'] = {
    label = 'Heroin',
    weight = 100,
    stack = true,
    close = true,
    description = 'Heroin powder',
    client = {
        image = 'heroin.png'
    }
},

['morphine'] = {
    label = 'Morphine',
    weight = 50,
    stack = true,
    close = true,
    description = 'Morphine injection',
    client = {
        image = 'morphine.png'
    }
},

['xanax'] = {
    label = 'Xanax',
    weight = 10,
    stack = true,
    close = true,
    description = 'Xanax pill',
    client = {
        image = 'xanax.png'
    }
},

['narcan'] = {
    label = 'Narcan',
    weight = 10,
    stack = true,
    close = true,
    description = 'Narcan spray',
    client = {
        image = 'narcan.png'
    }
},
```

{% endtab %}

{% tab title="TGIANN" %}
{% code fullWidth="false" %}

```lua
drugdetector = { label = "Drug Detector", weight = 1, type = "item", image = "drugdetector.png", unique = false, useable = true, shouldClose = true, description = "A device used to test for drugs in a person's system" },
drugdetector_used = { label = "Used Drug Detector", weight = 1, type = "item", image = "drugdetector_used.png", unique = true, useable = false, shouldClose = true, description = "A drug detector that has been used and contains test results" },
joint = { label = "Joint", weight = 1, type = "item", image = "joint.png", unique = false, useable = true, shouldClose = true, description = "A cannabis joint" },
cocaine = { label = "Cocaine", weight = 1, type = "item", image = "cocaine.png", unique = false, useable = true, shouldClose = true, description = "Cocaine powder" },
ecstasy = { label = "Ecstasy", weight = 1, type = "item", image = "ecstasy.png", unique = false, useable = true, shouldClose = true, description = "Ecstasy pill" },
meth = { label = "Methamphetamine", weight = 1, type = "item", image = "meth.png", unique = false, useable = true, shouldClose = true, description = "Methamphetamine crystal" },
heroin = { label = "Heroin", weight = 1, type = "item", image = "heroin.png", unique = false, useable = true, shouldClose = true, description = "Heroin powder" },
morphine = { label = "Morphine", weight = 1, type = "item", image = "morphine.png", unique = false, useable = true, shouldClose = true, description = "Morphine injection" },
xanax = { label = "Xanax", weight = 1, type = "item", image = "xanax.png", unique = false, useable = true, shouldClose = true, description = "Xanax pill" },
narcan = { label = "Narcan", weight = 1, type = "item", image = "narcan.png", unique = false, useable = true, shouldClose = true, description = "Narcan spray" },
```

{% endcode %}
{% endtab %}
{% endtabs %}

## STEP 5 - Inventory Metadata

{% hint style="info" %}
Most of inventory systems automatically detect metadata, but others require manual configuration.
{% endhint %}

{% tabs %}
{% tab title="TGIANN" %}
Insert this block of code in `tgiann-inventory/configs/configMetadataAdvance.lua`

{% code fullWidth="false" %}

```lua
drugdetector_used = function(metadata, currentLang)
        local L
        do
            local ok, labels = pcall(function()
                return exports['mst_drugdetector']:GetDrugDetectorLocaleLabels()
            end)
            if ok and type(labels) == 'table' then
                L = {
                    officer = labels.officer or "",
                    tested = labels.tested or "",
                    result = labels.result or "",
                    date_time = labels.date_time or "",
                }
            else
                L = { officer = "", tested = "", result = "", date_time = "" }
            end
        end

        local row = [[
        <div class="item_info_row">
            <div class="item_info_row_left">%s</div>
            <div class="item_info_row_right">%s</div>
        </div>
        ]]

        local rows = {}

        table.insert(rows, row:format(L.officer, metadata and (metadata.officer or "-") or "-"))
        table.insert(rows, row:format(L.tested, metadata and (metadata.tested or "-") or "-"))
        table.insert(rows, row:format(L.result, metadata and (metadata.testResult or "-") or "-"))
        table.insert(rows, row:format(L.date_time, metadata and (metadata.dateTime or "-") or "-"))

        local html = [[ <div class="item_info_container">%s</div> ]]
        return html:format(table.concat(rows, "\n"))
end,
```

{% endcode %}
{% endtab %}
{% endtabs %}

## STEP 6 - Not working?

We hope you won’t need this step, but if you do, feel free to join our [**Discord**](https://discord.mosotoscripts.com) and open a support ticket. :)
