API Reference

Server exports and item metadata provided by oxide-cocaine for integrations.

Server exports provided by oxide-cocaine, for developers integrating other resources (selling scripts, missions, leaderboards).

Any server resource can call these after oxide-cocaine has started.

Server Exports

GetPlayerLevel(source)

Returns the player's cocaine progression level (1-10 with the default level table).

local level = exports['oxide-cocaine']:GetPlayerLevel(source)

Returns 1 if the player has no character loaded or no cocaine progression row yet.

GetPlayerProgression(source)

Returns the player's full cocaine progression stats table.

local progression = exports['oxide-cocaine']:GetPlayerProgression(source)

Shape:

{
    level = 1,
    xp = 0,
    currentLevelXp = 0,      -- XP threshold of the current level
    nextLevelXp = 100,       -- XP threshold of the next level; nil at max level
    totalCreated = 0,
    totalSold = 0,
    unlocks = {              -- one entry per station, ordered by required level
        {
            level = 1,           -- the level this station unlocks at
            label = 'Coca Pool', -- friendly station name
            unlocked = true,     -- whether this player has reached it
        },
        -- ...
    },
}

Returns nil if the player's character identifier cannot be resolved (e.g. not fully loaded).

AddXP(source, amount)

Adds cocaine XP and runs the level-up check (so the player may level up from this call).

local ok = exports['oxide-cocaine']:AddXP(source, 25)

Returns true on success, false if the player has no character loaded or amount is missing, non-numeric, or not greater than zero.

oxide-drugselling calls this on every sale, so cocaine levels keep climbing as players sell.

AddSold(source, amount)

Adds to the player's total_sold counter for cocaine. Call this from your selling script so sales show up in /cocaine stats.

local ok = exports['oxide-cocaine']:AddSold(source, 3)

Returns true on success, false if the player has no character loaded or amount is missing, non-numeric, or not greater than zero.

AddSold only updates the sold counter — it does not award XP. To do both on a sale, call AddXP as well.

GetSetting(key)

Reads a live setting from the configuration (the values stored in the oxide_settings table and edited from /cocaine settings — see Configuration). The key is the top-level config name without the Config. prefix.

local requireOwnership = exports['oxide-cocaine']:GetSetting('RequireOwnership')
local cook = exports['oxide-cocaine']:GetSetting('Cook')   -- the whole Config.Cook group as a table

Returns the current value (any type — boolean, number, string, or table). Returns nil for an unknown key.

SetSetting(key, value)

Changes a live setting. The update applies on the server immediately, is saved to the database, and is synced to all clients — the same effect as changing it in the settings menu. The change persists across restarts.

local ok = exports['oxide-cocaine']:SetSetting('RequireOwnership', false)

Returns true. The key is the top-level config name without the Config. prefix, and value must be the whole value for that key (for a group like Cook, pass the entire group table).

Prefer GetSetting/SetSetting over reading or writing the oxide_settings database row directly — these keep the server, database, and connected clients in sync in one call.

Item Metadata

Finished items carry metadata your scripts can read through your inventory's normal metadata access. The key field for pricing is purity — the grade decided at the cook and carried through every later item.

ItemMetadata fields
coca_mash, coca_extractvariant, purity
cocaine, crackvariant, purity, description
cocaine_bag, crack_bagvariant, purity, description
cocaine_brickpurity, description

purity is one of Pure, High, Mid, Low, or Dirty. variant is the product key (cocaine or crack, and mash/extract on the intermediate items).

Integration Examples

Pay more for purer product in a selling script

-- In your sell handler, read the bag's purity off its metadata and scale the payout.
local PURITY_MULT = { Pure = 1.5, High = 1.25, Mid = 1.0, Low = 0.8, Dirty = 0.6 }

local function payForBag(source, basePrice, itemMetadata)
    local grade = (itemMetadata and itemMetadata.purity) or 'Mid'
    local price = math.floor(basePrice * (PURITY_MULT[grade] or 1.0))

    -- ...remove the bag and pay the player through your framework here...

    -- Then credit the sale back to cocaine progression:
    exports['oxide-cocaine']:AddSold(source, 1)
    exports['oxide-cocaine']:AddXP(source, 5)
end

Gate a feature behind cocaine level

local level = exports['oxide-cocaine']:GetPlayerLevel(source)
if level >= 5 then
    -- unlock a wholesale buyer, a bigger stash, etc.
end

Next Steps