Skip to main content
Every time drugs are sold, Drugs Creator asks your code first, right before the player gets paid. Your code can keep the price, set a new one or cancel the sale. It works for every selling method: NPC, corner, narcos, pushers, plane, boat and hired dealers. It’s the place to plug in your own economy: prices that change with the area, supply and demand, gang activity or the police on duty. You can do it in two ways. Pick the one you prefer, or use both.

The easy way: sv_integrations.lua

At the bottom of integrations/sv_integrations.lua there is a commented example. Move the BeforeDrugSale function out of the comment and edit it:
Function
If you updated from an older version and kept your own sv_integrations.lua, just paste the function at the bottom of the file. Without it, sales work as before.

From your own resource

If your economy lives in its own resource, register a hook from there:
Export
The second parameter is optional: it limits the hook to some selling methods and some drugs. Leave it out and the hook runs for every sale. exports.drugs_creator:removeSaleHook(hookId) removes it. When your resource stops, its hooks are removed on their own.
Start your resource after drugs_creator. If you restart Drugs Creator, it forgets the hooks: register them again when it starts.

What you return

When a sale is cancelled, the player keeps the drugs and gets no money. When you change the price, the notification, the Discord log, the dashboard statistics and the selling events all use your price. If more hooks are registered, they run one after the other: each one gets the price left by the one before.

The sale

Your function receives one table, sale, with everything about the sale:

Example

Return right away. Don’t use Wait or MySQL.await inside the hook: a hook that waits cancels the sale, and the server console says so. Keep your prices in memory and read them from there.
  • If your hook throws an error or returns something that isn’t a price, the sale goes on at the price it had, and the console shows a warning
  • Narcos: when a player opens the narcos menu, your hook is called with preview = true so the menu shows your price. It’s called again with preview = false when the sale really happens: change your stock or supply only then
  • Plane and boat call the hook once for each drug: you can cancel one drug and let the others sell
  • A cancelled hired dealer sale keeps the drugs in the dealer’s stock