The easy way: sv_integrations.lua
At the bottom ofintegrations/sv_integrations.lua there is a commented example. Move the BeforeDrugSale function out of the comment and edit it:
Function
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
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
- 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 = trueso the menu shows your price. It’s called again withpreview = falsewhen 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
