Flake Addiction
A configurable drug addiction system for FiveM. Real-time immunity tracking, withdrawal effects, overdose mechanics, a medication system, and a full in-game admin creator — all persisted to MySQL.
Overview
Flake Addiction adds a persistent, server-authoritative drug addiction layer to your FiveM server. Every drug is registered with its own immunity timer, addiction chance, withdrawal strength, and overdose threshold. As players consume drugs, their immunity decays in real time — and once immunity expires, withdrawal effects kick in until medication is used or enough time passes.
All addiction state is stored in MySQL and synced back to clients on connection, meaning addiction persists across reconnects and server restarts. An in-game creator panel (/addictioncreator) lets admins configure every aspect of each drug without touching a single file.
ESX Only
es_extended is started before flake_addiction.Features
- •Dynamic Drug Registration — Register any number of drugs via the creator panel or config.json with full schema control.
- •Immunity System — Each drug tracks remaining immunity time per player. Immunity decays continuously server-side.
- •Addiction Timers — Configurable addiction duration per drug. Players become addicted once immunity depletes past the threshold.
- •Withdrawal Effects — Screen effects, movement penalties, and camera shake fire automatically during withdrawal state.
- •Medication System — Register medication items that reduce or clear addiction for specific drugs.
- •Admin Creator Panel — Full in-game UI (/addictioncreator) to create, edit, and remove drug definitions.
- •Persistent Storage — Addiction state saved to MySQL — survives server restarts and player reconnects.
- •Real-Time Config Sync — Config changes broadcast live to all connected clients via server events.
- •Overdose Handling — Configurable overdose at high drug strength — applies severe effects or kills the player.
Requirements
| Dependency | Purpose | Required |
|---|---|---|
oxmysql | Async MySQL for addiction state persistence | Yes |
| ESX | Framework for players, items, and identity | Yes |
| ESX Inventory or OX Inventory | Item consumption and usable item registration | Yes |
Installation
Step 1 — Ensure the Resource
Place flake_addiction in your resources directory and add it to server.cfg after your framework and inventory:
ensure flake_addictionStep 2 — Import the SQL
Run the provided flake_addiction.sql file against your database:
CREATE TABLE IF NOT EXISTS `flake_addiction` (
`identifier` VARCHAR(60) NOT NULL,
`drug` VARCHAR(50) NOT NULL,
`remaining_time` INT NOT NULL DEFAULT 0,
PRIMARY KEY (`identifier`, `drug`)
);Step 3 — Add Items to Your Inventory
Add each drug and medication as a usable item in your inventory resource. The script registers usable callbacks automatically on startup — you only need the item definitions to exist. If you are using Windy City Drugs, a pre-built ox.txt item list is included in the resource root.
- •OX Inventory — import items from
windy city drugs ox.txtor add your own toox_inventory/data/items.lua. - •ESX Inventory — add items to your
es_extendeditems table and restart the resource.
Step 4 — Configure
Edit config.lua for core settings (UI colour, admin groups, translations) and optionally edit config.json to pre-populate drug definitions before first launch.
Step 5 — First-Run Setup
On first launch the creator will prompt you to apply a preset or start from scratch. See the Addiction Creator section for details.
File Structure
flake_addiction/ ├── client/ │ ├── main.lua -- Effects, animations, immunity loop │ └── creator.lua -- Admin creator panel client logic ├── server/ │ └── main.lua -- DB reads/writes, sync, item registration ├── config.lua -- Core settings, admin groups, translations ├── config.json -- Drug definitions (edited via creator) ├── flake_addiction.sql -- Database schema ├── fxmanifest.lua -- Resource manifest └── windy city drugs ox.txt -- Optional: OX item definitions
Ready
/addictioncreator to open the panel and configure your drugs. No restart is required after saving changes.Configuration
config.lua contains server-level settings. Drug definitions live in config.json and are managed through the in-game creator panel.
Core Settings
| Key | Description |
|---|---|
Config.UIColor | Hex colour for the creator panel accent (e.g. "#3b82f6") |
Config.AdminGroups | ESX groups permitted to use /addictioncreator (e.g. { "admin", "superadmin" }) |
Config.DrugImmunity | Global immunity decay rate in seconds per server tick — controls how fast addiction builds |
Config.UsableDrugs | Table of item names that trigger the addiction system when used from inventory |
Config.Medication | Table of medication item names and which drug they treat, with immunity restore amount |
Config.Translations | All player-facing strings — localise or rephrase as needed |
Drug Schema
Each drug entry in config.json follows this schema. The creator generates valid JSON automatically — edit manually only if needed:
{
"label": "Cocaine",
"animation": "sniff",
"drugStrength": 75,
"healthEffects": {
"healthBoost": 10,
"armorBoost": 0
},
"addiction": {
"chance": 0.65,
"time": 3600
},
"effect": {
"duration": 300,
"screenFX": "DrugsMichaelAliensFight",
"speedMultiplier": 1.3,
"cameraShakeIntensity": 0.4
}
}| Field | Type | Description |
|---|---|---|
label | string | Display name shown in the creator UI and notifications |
animation | string | Use animation type: pill, smoke, syringe, or sniff |
drugStrength | number | Overdose threshold — reaching 100 triggers overdose mechanics |
healthEffects.healthBoost | number | HP added when the drug is consumed (0 for no boost) |
healthEffects.armorBoost | number | Armor added when the drug is consumed (0 for no boost) |
addiction.chance | float | Probability (0.0–1.0) that a single use increments the addiction counter |
addiction.time | number | Immunity duration in seconds awarded per use |
effect.duration | number | How long (seconds) the active effects persist after use |
effect.screenFX | string | GTA timecycle / post-process effect name to apply while high |
effect.speedMultiplier | float | Sprint speed multiplier during the effect window (1.0 = normal) |
effect.cameraShakeIntensity | float | Camera shake strength during the effect window (0.0 = none) |
Medication Schema
Medication items are registered under Config.Medication in config.lua:
Config.Medication = {
{
item = "methadone",
treatsDrug = "heroin",
restores = 1800, -- seconds of immunity restored on use
clears = false, -- set true to fully clear addiction
},
{
item = "rehab_pill",
treatsDrug = "cocaine",
restores = 0,
clears = true,
},
}Usage & Effects
When a player uses a registered drug item, the script runs through the following pipeline:
- 1Item Used — The ESX usable callback fires and the server validates the player has the item.
- 2Animation Plays — The client plays the appropriate use animation (pill swallow, smoke inhale, syringe inject, or sniff).
- 3Effects Applied — Screen FX, speed multiplier, and camera shake activate for the configured duration.
- 4Health / Armor — If healthEffects are configured, the boost is applied immediately after the animation.
- 5Addiction Roll — The server rolls addiction.chance. On success, immunity time is credited to the player's row in flake_addiction.
- 6Immunity Tracked — Immunity decays continuously. When remaining_time hits 0, the player enters withdrawal.
- 7Overdose Check — If drugStrength accumulates to 100 within the effect window, overdose effects fire.
Animations
| Type | Animation | Use Case |
|---|---|---|
pill | Hand-to-mouth swallow animation | Pills, capsules, edibles |
smoke | Lighter + inhale smoke animation | Crack pipes, cigarettes, blunts |
sniff | Bent-down snort animation | Cocaine, ketamine, powders |
syringe | Arm inject animation with prop | Heroin, meth, injectables |
Overdose
If a player's accumulated drugStrength reaches 100 within a single effect window, the overdose sequence triggers:
- •Severe screen effects and maximum camera shake are applied.
- •Movement is slowed to a crawl.
- •Health drains at an accelerated rate.
- •If health reaches zero before a medication item is used, the player dies.
Overdose Kills
drugStrength values.Withdrawal Effects
Once remaining_time reaches zero for an addicted player, withdrawal begins automatically. The following effects are applied on a recurring server tick until immunity is restored:
- •Periodic screen blur and desaturation effects.
- •Randomised camera shaking at low intensity.
- •Slow, gradual health drain (configurable per drug).
- •Reduced movement speed.
Withdrawal ends as soon as the player uses the drug again (restoring immunity) or uses an appropriate medication item.
Items
Flake Addiction does not ship with a fixed item list — drug items are whatever you register in Config.UsableDrugs and the creator panel. If your server uses Windy City Drugs, a ready-made OX Inventory item definition file is included:
Included item file
windy city drugs ox.txt
Paste contents into ox_inventory/data/items.lua
Custom Items
Config.UsableDrugs, and create a matching entry in the creator panel.Addiction Creator
The in-game creator panel is the primary interface for managing drug definitions. All changes are written to config.json and broadcast live to connected clients — no restart required.
Opening the Panel
Type /addictioncreator in chat. Access is restricted to groups defined in Config.AdminGroups.
First-Run Setup
On first launch (when config.json is empty) the panel prompts you to choose between two options:
- •Apply Preset — loads the bundled Windy City Drugs preset with pre-configured values for common drug items. Good starting point for most servers.
- •Decline / Start Blank — opens an empty creator so you can build your drug list from scratch.
Presets are Editable
Panel Features
- •Create a new drug with full schema fields via guided form inputs.
- •Edit any existing drug — changes save instantly to
config.jsonand sync to clients. - •Delete a drug — removes it from
config.jsonand clears it from active client configs. - •Preview animation type and screen FX name before saving.
Reset Installation
To trigger the first-run preset prompt again (e.g. to switch from a blank setup to the preset), use:
/resetaddictioninstallThis clears the config.json and reopens the preset selection prompt on next /addictioncreator launch.
Database
The resource uses a single table — flake_addiction — to persist immunity state per player per drug. Each row represents one active addiction relationship.
| Column | Type | Key | Description |
|---|---|---|---|
identifier | VARCHAR(60) | PRIMARY | ESX player identifier (license, steam, etc.) |
drug | VARCHAR(50) | PRIMARY | Drug name matching the config.json key |
remaining_time | INT | — | Remaining immunity in seconds. 0 = in withdrawal. Decrements each server tick. |
Composite Primary Key
identifier and drug, so one player can be addicted to multiple drugs simultaneously with independent immunity timers.Rows are inserted on first drug use and updated on each subsequent use. When remaining_time reaches 0 the server applies withdrawal events to that client. Rows are not deleted automatically — they remain as historical records unless you run /clearaddiction [identifier].
Events
All events are prefixed with flake_addiction: and can be listened to for custom integrations.
Client Events
| Event | Payload | Description |
|---|---|---|
useDrug | drug (string) | Triggers the use pipeline for the specified drug on the local client. |
useMedication | item (string) | Triggers the medication consumption flow for the specified item. |
data | addictions (table) | Delivers the player's full addiction data from the server on connect or refresh. |
syncConfig | config (table) | Pushes the latest drug config from config.json to all clients. Fired after creator saves. |
Server Events
| Event | Payload | Description |
|---|---|---|
requestSync | — | Client requests its addiction data on first load. Server responds with the data event. |
Server-Side Validation
Commands
| Command | Arguments | Description | Permission |
|---|---|---|---|
/addictioncreator | — | Open the in-game addiction creator panel | Admin |
/clearaddiction | [identifier] | Clear all addiction data for the specified player identifier | Admin |
/resetaddictioninstall | — | Wipe config.json and re-trigger the first-run preset prompt | Admin |
clearaddiction_console | [identifier] | Server console command — same as /clearaddiction but from the console | Console |
Troubleshooting
| Issue | Fix |
|---|---|
| Drug item not usable | Ensure the item is added to your inventory resource and matches the name in Config.UsableDrugs exactly (case-sensitive). |
| Addiction not saving across restarts | Check that oxmysql is started before flake_addiction and that the SQL table was imported correctly. |
| No effects on drug use | Verify the drug entry exists in config.json and the screenFX name is a valid GTA V effect string. |
| Withdrawal not triggering | Confirm addiction.time is not set to an extremely high value and that the server tick is running. Check server console for errors. |
| /addictioncreator denied | Your ESX group must be listed in Config.AdminGroups. Verify with GetPlayerGroup in the console. |
| Preset not loading on first run | Run /resetaddictioninstall to wipe config.json and re-trigger the setup prompt. |
| Medication item has no effect | Check that treatsDrug in the medication config exactly matches the drug key in config.json. |
| Overdose fires unexpectedly | Lower drugStrength for the drug in the creator panel. A value below 30 makes overdose very unlikely in normal use. |
Developed by Flake Development. For support, open a ticket in our Discord.
