How to Build a Drug Selling Script for a GTA Roleplay Server With AI
NPC drug selling is the entry-level crime loop on most roleplay servers: a player carries a sellable item, approaches a wandering ped, offers a deal, and the ped buys, refuses, or panics and calls the police. It's simple to build, endlessly tunable, and pairs naturally with gangs, turf, and laundering. Done well it rewards risk and movement; done badly it's a money printer that ruins the economy.
This guide builds the full loop finding a nearby ped, the offer interaction, accept/refuse/flee outcomes, payment in dirty money, police alerts, cooldowns, and optional leveling for ESX and QBCore. PlayDeck teaches you to build this with AI: you describe the drugs, prices, zones, and risk percentages, steer the AI as it writes the ped targeting and the server-side payout, and verify it can't be farmed before selling it on Tebex.
Find a sellable ped and start the offer
The loop starts by finding a valid nearby NPC. On the client, scan for peds around the player (GetGamePool 'CPed'), filter to wandering civilians (not in vehicles, not players, not mission peds, not police), and pick the closest within range. Restrict selling to configured zones so it happens in the right neighborhoods, not in front of the police station check the player's coordinates against your zone polygons before allowing an offer.
Trigger the offer with a key press or ox_target on the ped while holding the drug. Play a deal/handshake animation and a short progress bar so it isn't instant this is the window where things can go wrong and police can intervene. The client only requests a sale; it tells the server which ped and which drug, and the server decides the outcome. When you steer an AI, give it the zone list and the ped filter rules; it writes the scan and the interaction, you confirm the zone check is enforced.
Resolve accept, refuse, or flee on the server
Every outcome is decided server-side. The server verifies the player actually holds the drug, is in a valid zone, and is off cooldown, then rolls the result against your configured chances: the ped accepts (pay out and consume one drug), refuses (no sale, short cooldown), or panics and flees while alerting police. Tune these percentages a higher refuse/flee chance raises risk and slows farming.
On accept, the server removes one unit of the drug from the inventory and credits dirty/black money within a configured price range (randomized so it's not perfectly predictable). On flee, fire a police alert with the location. Never let the client report 'the ped accepted and here's my money' the client requests, the server validates possession, rolls the outcome, and grants the reward. Describe the accept/refuse/flee percentages and price range to your AI; it implements the roll, and you ensure the drug is consumed and money granted only on the server.
Add police alerts, cooldowns, and leveling
Risk comes from cops. On a flee outcome (or a configurable percentage of any sale), fire a dispatch alert with a blip near the player so police can respond. A per-player cooldown between sales stored server-side stops machine-gun selling, and a per-ped flag stops selling to the same NPC repeatedly. Together these set the pace of the loop.
Leveling adds progression: track a player's drug-selling XP, and let higher levels unlock better prices, harder drugs, or more zones, while keeping low levels deliberately unprofitable so newcomers can't rush it. Store XP server-side in the player's metadata or a table. When you describe the progression to an AI XP per sale, unlock thresholds, price multipliers it wires the leveling, and you verify XP and unlocks are validated server-side, never sent by the client.
Balance the economy and keep it legitimate
Drug selling is the most-abused money source on amateur servers because it's repeatable. Keep it honest: pay dirty money that needs laundering at a cut (see the banking guide), make refuse/flee frequent enough to matter, enforce cooldowns and zones, and price a full sales run below a comparable legal job once you factor in arrest risk and the laundering loss. The goal is a tense, profitable-if-careful loop, not a printer.
Tie it into the wider crime ecosystem: gangs can control the zones, the product comes from growing or cooking, and the proceeds get laundered. That web is what makes a server's underworld feel real. And keep it clean commercially and within the rules you build original scripts, monetize them on Tebex with a Cfx.re license and escrow, and never ship leaked or pay-to-win versions. PlayDeck's whole approach is teaching you to build these systems yourself, with AI, the right way.
Frequently asked questions
How do I make selling only work in certain areas?
Define zones as polygons or radii in config and check the player's coordinates against them on the server before allowing an offer. Selling outside a zone is rejected, which keeps the trade in the right neighborhoods.
Should the ped always buy?
No. Roll accept/refuse/flee on the server against configured chances. Refusals and flees create risk and slow farming, and a flee should alert police that tension is the point of the loop.
What money should drug sales pay?
Dirty (black) money that must be laundered at a cut. Instantly spendable cash from drugs floods the economy and removes risk. Laundering is both a sink and a roleplay step.
How do I stop players farming the same ped?
Use a per-player cooldown stored server-side plus a per-ped flag so a given NPC won't keep buying. Combine with zone limits and refuse/flee chances to pace the loop.
Can AI build the NPC selling loop?
Yes. You define drugs, prices, zones, and accept/refuse/flee odds; the AI writes the ped scan, the interaction, and the server-side outcome roll. You verify possession checks, cooldowns, and dirty-money payout the workflow PlayDeck teaches.