# qb-drugs: deliveries, dealer shops and NPC sales

The official `qb-drugs` implements NPC corner selling and delivery jobs with configurable dealers and payout conditions. This page follows [upstream commit 51052d1](https://github.com/qbcore-fivem/qb-drugs/tree/51052d139bc482d9d0e94d4f47680b241e866bba). It does not implement the fictional drug labs, seizure registry or investigation database previously described here.

## Installation and data storage

Start `qb-core`, `oxmysql`, `PolyZone` and inventory dependencies, then `qb-drugs`. The [manifest](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/fxmanifest.lua) loads distinct client/server files for `deliveries` and `cornerselling`. Ensure the shared item catalog contains every drug/product item you configure.

The packaged [`qb-drugs.sql`](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/qb-drugs.sql) creates a **`dealers`** table with dealer identity, coordinates, times and creator. There is **no** `drug_labs` or `drug_seizures` table in the upstream schema. Back up existing dealer data before migrating a fork.

## Configuration

The top-level [`Config` table](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/config.lua) includes:

| Key | Role |
| --- | --- |
| `Config.Debug` | Diagnostic output |
| `Config.NearbyDeliveries` / `DeliveryWithin` | Delivery proximity limit |
| `Config.Dealers` | Dealer names, hours, positions and product list |
| `Config.UseTarget` | Target interactions from `UseTarget` convar |
| `Config.PoliceCallChance` | NPC sale alert chance |
| `Config.Products` | Shop stock, item names, price and minimum reputation |
| `Config.SuccessChance`, `ScamChance`, `RobberyChance` | Corner sale outcomes |
| `Config.MinimumDrugSalePolice` | Required active police |
| `Config.DrugsPrice` | Drug sale pricing |
| `Config.UseMarkedBills` | Cash/marked-bill payout mode |
| `Config.DeliveryRepGain` / `DeliveryRepLoss` | Reputation changes |
| `Config.DeliveryItems` / `DeliveryLocations` | Requested items and routes |

~~~lua filename="config.lua"
-- Modify these existing source keys:
Config.NearbyDeliveries = false
Config.DeliveryWithin = 2000
Config.PoliceCallChance = 99
Config.UseMarkedBills = false
~~~

No generic `Config.Labs`, `Config.ProductionTime`, `Config.Investigation` or `Config.Penalties` is present in the reviewed source.

## Real external server export

The [delivery server](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/server/deliveries.lua) exposes `GetDealers`:

~~~lua filename="server.lua"
local dealers = exports['qb-drugs']:GetDealers()
-- Read only; avoid mutating the resource's shared dealer table.
for name in pairs(dealers or {}) do
    print(('Configured dealer: %s'):format(name))
end
~~~

It does not export `ProcessSeizure`, `GetMarketPrice` or a generic production-lab API. Dealer management commands include `newdealer`, `deletedealer`, `dealers` and `dealergoto`; examine their QBCore permissions before allowing staff to use them.

## Event and permission boundaries

The server uses `qb-drugs:server:RequestConfig` as a QBCore callback, plus `updateDealerItems`, `giveDeliveryItems`, `successDelivery` and `dealerShop` under the same server prefix. The corner-selling implementation registers `qb-drugs:server:cornerselling:getAvailableDrugs`, `sellCornerDrugs`, `robCornerDrugs` and `giveStealItems`.

These internal event paths can grant items or money. Treat client-supplied quantities, delivery state, sale totals and dealer coordinates as untrusted and validate against the server's own rules. Never expose arbitrary `TriggerServerEvent` examples that pay rewards.

## Troubleshooting

| Symptom | First check |
| --- | --- |
| Dealer list disappears on restart | Imported `dealers` SQL table and database |
| Selling at an NPC does not work | Correct drug items, police minimum and sale outcome configuration |
| Dealer shop empty | `Config.Products`, item names and reputation requirements |
| Delivery never completes | `DeliveryLocations`, inventory contents and server callback |
| No such export `GetMarketPrice` | Not registered; only `GetDealers` is exported here |

## Update checklist

1. Pin `qb-drugs`, `qb-core`, `qb-inventory` and SQL schema revisions.
2. Preserve `dealers` and local configuration when updating.
3. Test delivery/sale with valid and invalid items, amounts and permissions.
4. Audit server rewards and dealer access for forged or repeated events.

## Sources

[Repository](https://github.com/qbcore-fivem/qb-drugs/tree/51052d139bc482d9d0e94d4f47680b241e866bba) · [Configuration](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/config.lua) · [Dealer SQL](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/qb-drugs.sql) · [Delivery code](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/server/deliveries.lua) · [Corner selling](https://github.com/qbcore-fivem/qb-drugs/blob/51052d139bc482d9d0e94d4f47680b241e866bba/server/cornerselling.lua)
