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.

FiveMESXMySQLLua 5.4
Purchase Script
flakedev.com

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

Flake Addiction currently supports the ESX framework only. QB-Core support is not included. Ensure es_extended is started before flake_addiction.

Features

  • Dynamic Drug RegistrationRegister any number of drugs via the creator panel or config.json with full schema control.
  • Immunity SystemEach drug tracks remaining immunity time per player. Immunity decays continuously server-side.
  • Addiction TimersConfigurable addiction duration per drug. Players become addicted once immunity depletes past the threshold.
  • Withdrawal EffectsScreen effects, movement penalties, and camera shake fire automatically during withdrawal state.
  • Medication SystemRegister medication items that reduce or clear addiction for specific drugs.
  • Admin Creator PanelFull in-game UI (/addictioncreator) to create, edit, and remove drug definitions.
  • Persistent StorageAddiction state saved to MySQL — survives server restarts and player reconnects.
  • Real-Time Config SyncConfig changes broadcast live to all connected clients via server events.
  • Overdose HandlingConfigurable overdose at high drug strength — applies severe effects or kills the player.

Requirements

DependencyPurposeRequired
oxmysqlAsync MySQL for addiction state persistenceYes
ESXFramework for players, items, and identityYes
ESX Inventory or OX InventoryItem consumption and usable item registrationYes

Installation

Step 1 — Ensure the Resource

Place flake_addiction in your resources directory and add it to server.cfg after your framework and inventory:

server.cfg
ensure flake_addiction

Step 2 — Import the SQL

Run the provided flake_addiction.sql file against your database:

flake_addiction.sql
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.txt or add your own to ox_inventory/data/items.lua.
  • ESX Inventory — add items to your es_extended items 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

Start your server and connect. Type /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

KeyDescription
Config.UIColorHex colour for the creator panel accent (e.g. "#3b82f6")
Config.AdminGroupsESX groups permitted to use /addictioncreator (e.g. { "admin", "superadmin" })
Config.DrugImmunityGlobal immunity decay rate in seconds per server tick — controls how fast addiction builds
Config.UsableDrugsTable of item names that trigger the addiction system when used from inventory
Config.MedicationTable of medication item names and which drug they treat, with immunity restore amount
Config.TranslationsAll 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:

config.json (drug entry)
{
  "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
  }
}
FieldTypeDescription
labelstringDisplay name shown in the creator UI and notifications
animationstringUse animation type: pill, smoke, syringe, or sniff
drugStrengthnumberOverdose threshold — reaching 100 triggers overdose mechanics
healthEffects.healthBoostnumberHP added when the drug is consumed (0 for no boost)
healthEffects.armorBoostnumberArmor added when the drug is consumed (0 for no boost)
addiction.chancefloatProbability (0.0–1.0) that a single use increments the addiction counter
addiction.timenumberImmunity duration in seconds awarded per use
effect.durationnumberHow long (seconds) the active effects persist after use
effect.screenFXstringGTA timecycle / post-process effect name to apply while high
effect.speedMultiplierfloatSprint speed multiplier during the effect window (1.0 = normal)
effect.cameraShakeIntensityfloatCamera shake strength during the effect window (0.0 = none)

Medication Schema

Medication items are registered under Config.Medication in config.lua:

config.lua (medication entry)
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:

  1. 1Item UsedThe ESX usable callback fires and the server validates the player has the item.
  2. 2Animation PlaysThe client plays the appropriate use animation (pill swallow, smoke inhale, syringe inject, or sniff).
  3. 3Effects AppliedScreen FX, speed multiplier, and camera shake activate for the configured duration.
  4. 4Health / ArmorIf healthEffects are configured, the boost is applied immediately after the animation.
  5. 5Addiction RollThe server rolls addiction.chance. On success, immunity time is credited to the player's row in flake_addiction.
  6. 6Immunity TrackedImmunity decays continuously. When remaining_time hits 0, the player enters withdrawal.
  7. 7Overdose CheckIf drugStrength accumulates to 100 within the effect window, overdose effects fire.

Animations

TypeAnimationUse Case
pillHand-to-mouth swallow animationPills, capsules, edibles
smokeLighter + inhale smoke animationCrack pipes, cigarettes, blunts
sniffBent-down snort animationCocaine, ketamine, powders
syringeArm inject animation with propHeroin, 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

Overdose is fatal if left untreated. Ensure your server has a way for other players to administer medication or call EMS before enabling high 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

You can register any item name as a usable drug — the script is not locked to a specific item set. Add the item to your inventory, list it in 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

Applying the preset does not lock you in. You can edit or delete any preset drug from the panel immediately after applying.

Panel Features

  • Create a new drug with full schema fields via guided form inputs.
  • Edit any existing drug — changes save instantly to config.json and sync to clients.
  • Delete a drug — removes it from config.json and 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:

in-game chat
/resetaddictioninstall

This 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.

ColumnTypeKeyDescription
identifierVARCHAR(60)PRIMARYESX player identifier (license, steam, etc.)
drugVARCHAR(50)PRIMARYDrug name matching the config.json key
remaining_timeINTRemaining immunity in seconds. 0 = in withdrawal. Decrements each server tick.

Composite Primary Key

The primary key spans both 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

EventPayloadDescription
useDrugdrug (string)Triggers the use pipeline for the specified drug on the local client.
useMedicationitem (string)Triggers the medication consumption flow for the specified item.
dataaddictions (table)Delivers the player's full addiction data from the server on connect or refresh.
syncConfigconfig (table)Pushes the latest drug config from config.json to all clients. Fired after creator saves.

Server Events

EventPayloadDescription
requestSyncClient requests its addiction data on first load. Server responds with the data event.

Server-Side Validation

All immunity writes and addiction chance rolls happen server-side. Never trigger database writes directly from the client — route through the provided server events.

Commands

CommandArgumentsDescriptionPermission
/addictioncreatorOpen the in-game addiction creator panelAdmin
/clearaddiction[identifier]Clear all addiction data for the specified player identifierAdmin
/resetaddictioninstallWipe config.json and re-trigger the first-run preset promptAdmin
clearaddiction_console[identifier]Server console command — same as /clearaddiction but from the consoleConsole

Troubleshooting

IssueFix
Drug item not usableEnsure the item is added to your inventory resource and matches the name in Config.UsableDrugs exactly (case-sensitive).
Addiction not saving across restartsCheck that oxmysql is started before flake_addiction and that the SQL table was imported correctly.
No effects on drug useVerify the drug entry exists in config.json and the screenFX name is a valid GTA V effect string.
Withdrawal not triggeringConfirm addiction.time is not set to an extremely high value and that the server tick is running. Check server console for errors.
/addictioncreator deniedYour ESX group must be listed in Config.AdminGroups. Verify with GetPlayerGroup in the console.
Preset not loading on first runRun /resetaddictioninstall to wipe config.json and re-trigger the setup prompt.
Medication item has no effectCheck that treatsDrug in the medication config exactly matches the drug key in config.json.
Overdose fires unexpectedlyLower 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.