API Reference

Server exports and events provided by oxide-pills — progression and master ranks, XP and sales, buyer pricing through PriceFor, live settings, the level-up, rank-up and batch-seized events — plus the metadata every pill item carries.

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

Any server resource can call the exports, or listen for the events, after oxide-pills has started.

Server Exports

GetPlayerLevel(source)

Returns the player's pill level (1–10 with the default level table).

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

Returns 1 if the player has no character loaded. A character with no pill progression yet gets a level 1 row created.


GetPlayerProgression(source)

Returns the player's full pill progression stats.

local progression = exports['oxide-pills']: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,        -- pills kept from sorted trays
    totalSold = 0,
    unlocks = {              -- stations, product lines and perks, ordered by level
        {
            level = 1,                -- the level it unlocks at
            label = 'Crank Press',    -- friendly name
            unlocked = true,          -- whether this player has reached it
        },
        -- ...
    },
    journal = {              -- the lab journal (see Features, "The lab journal and personal bests")
        bestQuality = 0,          -- best quality of their own batches read at the light box (0-100)
        bestGrade = nil,          -- that quality as a grade key ('excellent', 'good', 'fair', 'poor', 'bad'); nil until a reading
        bestMatch = 0,            -- best counterfeit match read on their own batches (0-100)
        batches = 0,              -- batches made
        inspected = 0,            -- their own batches they've inspected at the light box
        firsts = 0,               -- first-time bonuses claimed
        counterfeitPassed = false, -- whether bestMatch has reached Config.LabXp.counterfeitPassAt
    },
}

The export always includes bestQuality and bestMatch. /pills stats leaves the numbers out for players whose level only shows grades.

Line mastery, lab goals and master ranks aren't part of this export. Players see them in the Lab Profile (/pills stats). For the master rank, use GetPlayerRank.

Returns nil if the player's character identifier can't be found (for example, not fully loaded).


GetPlayerRank(source)

Returns the player's master rank past the top level, and its title.

local rank, title = exports['oxide-pills']:GetPlayerRank(source)
if rank > 0 then
    print(('Player %d is %s (rank %d)'):format(source, title, rank))
end

Parameters:

NameTypeDescription
sourcenumberThe player's server ID

Returns:

  • rank (number): the master rank, from 1 up to the number of ranks (5 by default). 0 when the player hasn't reached the first rank, while master ranks are switched off, or when the player has no character loaded.
  • title (string or nil): the rank's title, for example 'Master Presser II', or the title you set for that rank in Players → Master Ranks. nil whenever rank is 0.

The rank is worked out from the player's total XP every time, so it's always current. The export doesn't say which perks the player has picked.


AddXP(source, amount)

Adds pill XP the same way pills' own stages do. The level is checked, so the player may level up from this call, and they see the "+XP" pop-up and, on a level-up, the level-up banner (when those are switched on under Players → Lab XP). A level-up also raises oxide-pills:server:levelUp, and a new master rank raises oxide-pills:server:rankUp. XP from this export never claims a first-time bonus, and never counts toward line mastery or lab goals. It does count toward master ranks, and it's sent to the skills mirror when one is set (Players → Lab XP → Skills mirror).

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

Parameters:

NameTypeDescription
sourcenumberThe player's server ID
amountnumberXP to add, rounded to the nearest whole number. Must be greater than zero.

Returns: boolean. true when the XP was granted. false if the player has no character loaded, amount is missing, not a number, or not greater than zero (including an amount that rounds to 0), or their progression couldn't be loaded from the database.

oxide-drugselling calls this on every pill sale. It also raises its own oxide-drugselling:drugSold server event for each sale, which pills listens to: the sale builds the batch's brand reputation, adds to the seller's pills sold on that product line, and counts toward their street sale goals. Pills only accepts that event from oxide-drugselling itself. If any other resource raises it, pills ignores it and logs a security warning naming the resource.


AddSold(source, amount)

Adds to the player's sold counter for pills, so sales show in /pills stats.

local ok = exports['oxide-pills']:AddSold(source, 12)

Returns: boolean, with the same rules as AddXP.

AddSold only updates the counter. It doesn't award XP (call AddXP too) and it doesn't build brand reputation. Brand reputation only grows from sales made through oxide-drugselling and from delivery run drops.


PriceFor(metadata, context)

The price multiplier a street buyer puts on a stack of pills. This is what oxide-drugselling calls (as an export_multiplier pricing modifier in its Config.Drugs.pills) to price every pill sale. It reads the batch's hidden stats on the server; the numbers never leave it.

local multiplier, details = exports['oxide-pills']:PriceFor(itemMetadata, { npcModel = GetEntityModel(buyerPed) })

Parameters:

NameTypeDescription
metadatatableThe pill item's metadata (it needs batch)
contexttableThe sale. npcModel (number, the buyer's model hash) decides which buyer type is buying.

Returns:

  • multiplier (number): multiply your base price by this. It's rounded to the nearest 0.05, so a price reads as good or bad without giving away the hidden stats. 1.0 when the item has no known batch, or when npcModel is missing or 0.
  • details (table or nil): one line for a sell panel, saying who the buyer is and what they thought. nil when the multiplier is the plain 1.0 fallback.
{
    {
        label = 'Club kid',              -- the buyer type
        value = 'Likes the faces',       -- what they thought
        bonus = 0.2,                     -- multiplier - 1.0
        color = 'text-emerald-400',      -- text-emerald-400 when they liked it, text-orange-400 when not
        type = 'variant',
    },
}

The multiplier includes the batch's quality, its packing, its product line, whether it's hot, and its brand's reputation. See Selling.


GetSetting(key)

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

local ownership = exports['oxide-pills']:GetSetting('RequireOwnership')
local delivery = exports['oxide-pills']:GetSetting('Delivery')   -- the whole Config.Delivery table

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


SetSetting(key, value)

Changes a live setting. It applies on the server straight away, is saved to the database, and is sent to every client. It's the same as saving it in the settings menu, and it lasts through restarts.

exports['oxide-pills']:SetSetting('RequireOwnership', false)

Parameters:

NameTypeDescription
keystringThe top-level config name without Config.
valueanyThe whole new value for that key. For a table like Delivery, pass the entire table.

Returns: true once the setting is applied and saved. It returns false, and the setting keeps its old value, when:

  • settings are still loading at startup
  • the value holds a number that is not finite (NaN or infinity)
  • the value can't be saved to the database

Only true or false comes back, never a reason. A warning or error in the server console says why it was refused.

SetSetting doesn't check the value against the menu's limits the way the settings menu does, so pass a complete, valid value. Only use it for keys that appear in the settings menu. Skill and Buyers are meant to be read from the config file (see Configuration).

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

Server Events

oxide-pills:server:levelUp

Raised on the server every time an online player goes up a pill level: from their own work, from AddXP, and from /pills setxp, /pills setlevel or /pills setrank when they raise the level. It's a server-side event (not sent to clients), so listen for it with AddEventHandler in a server script.

AddEventHandler('oxide-pills:server:levelUp', function(src, level, previousLevel)
    print(('Player %d reached pill level %d (was %d)'):format(src, level, previousLevel))
end)

Parameters:

NameTypeDescription
srcnumberThe player's server ID
levelnumberTheir new pill level
previousLevelnumberThe level they had before
  • Gaining several levels at once raises it once, with the new level.
  • It isn't raised when a level goes down (/pills setxp can lower it).
  • It isn't raised for a player who wasn't online when the XP landed, for example a drum tumbler run that finished after they left the server. Their level still goes up; nothing is announced.
  • It's raised even when Level-up message is turned off under Players → Lab XP.

oxide-pills:server:rankUp

Raised on the server every time an online player reaches a new master rank: from their own work, from AddXP, and from /pills setxp or /pills setrank when they raise the rank. Listen for it with AddEventHandler in a server script.

AddEventHandler('oxide-pills:server:rankUp', function(src, rank, previousRank)
    local _, title = exports['oxide-pills']:GetPlayerRank(src)
    print(('Player %d reached master rank %d, %s (was %d)'):format(src, rank, title or '?', previousRank))
end)

Parameters:

NameTypeDescription
srcnumberThe player's server ID
ranknumberTheir new master rank
previousRanknumberThe rank they had before (0 for none)
  • Reaching several ranks at once raises it once, with the new rank.
  • It isn't raised when a rank goes down, or for a player who wasn't online when the XP landed.
  • It isn't raised while master ranks are switched off.
  • It's raised even when Level-up message is turned off under Players → Lab XP.
  • A grant that takes a player up a level and a rank at once raises levelUp and rankUp.

oxide-pills:server:batchSeized

Raised on the server for every stack of pills an officer logs as evidence in Pill ID (the Log the pills I'm carrying button; see Features). One logging raises it once per stack, so an officer carrying three stacks raises it three times. Stacks that were already logged are skipped and don't raise it.

AddEventHandler('oxide-pills:server:batchSeized', function(data)
    print(('Officer %d logged %d tablets of batch %s (%s)'):format(data.officer, data.count, data.batch, data.brand or data.line))
end)

Parameters: one table, data:

FieldTypeDescription
batchstringThe batch ID the pills carry
linestringThe product line: party, bar, blues, perc or capsule
brandIdnumber or nilThe brand's ID, on branded pills. nil for unbranded pills.
brandstring or nilThe brand's name, as it's shown on the pill. nil for unbranded pills.
countnumberHow many tablets were in the stack
coordstable{ x, y, z }: where the officer was standing when they logged it
officernumberThe logging officer's server ID
destroyedbooleantrue when the pills were removed from the officer's inventory (Players → World → Police evidence), false when they were kept and marked as evidence

It never says who made the pills. There's no maker, no press serial and no press owner in it, even with the press serial trail switched on. Use it for things that don't need one: an MDT entry, a police reward, a log.

Item Metadata

Pill items carry metadata your scripts can read through your inventory's normal metadata access. The quality numbers are never in the metadata. They stay on the server, keyed by the batch ID, so they can't be read from an inventory. Use PriceFor if you need a batch's value.

Finished pills

party_pill, bar_pill, blue_pill, perc_pill, molly_capsule, and their packed items (bar_pill_bag, bar_pill_bottle, bar_pill_blister and so on; see Installation):

FieldDescription
batchThe batch ID. Every pill from one sorted tray shares it.
lineparty, bar, blues, perc or capsule
tintThe party pill colour (0–7)
stampThe face: plain (blank), ref (the line's reference imprint) or brand
brandThe brand's name, on branded party pills (public: it's on the face)
symbolThe brand's symbol, on branded party pills
descriptionThe batch's impression, for example "These look clean." For bottles and blisters, the label or card text too.
bagged1 when packed in a baggie
packed'bottle' or 'blister' when packed that way
labelThe bottle label template key, on bottled pills
coated1 on pan-coated pills
evidence1 once police have logged the stack as evidence

Pills of the same batch but different packing are separate items: loose pills are the base item, packed ones the line's packed item. The count is always tablets.

Other items

ItemMetadata fields
pill_milledgrind, fines, active (the raw active it came from), lot (mystery powder only), identified (after a reagent test), description
pill_blendformula, line, active, lot, activeRatio, binderRatio, lubeRatio, fillerRatio, grind, fines, uniformity, tint, granulation (after the sieve), tumbled (1 after the drum tumbler), description
punch_die_setwear, line (the shape it's cut for; none means party), stamp, brand (brand ID), serial (an opaque ID given the first time the die goes on a press, so the server can follow its wear), description
reagent_kituses (tests left), description
mystery_powderlot, identified (after a reagent test)
pill_rejectsline, lot

A mystery powder lot is an opaque ID. What it really is lives only on the server until a reagent test reveals it.

Integration Examples

Gate a feature behind pill level

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

Unlock something for master ranks

local rank = exports['oxide-pills']:GetPlayerRank(source)
if rank >= 3 then
    -- a rank 3 Master Presser gets access to your top-tier supplier
end

Count seized tablets per officer

-- Server script. Keeps a running total of the tablets each officer has logged as evidence,
-- for a shift report or a reward you pay out later.
local seizedBy = {}

AddEventHandler('oxide-pills:server:batchSeized', function(data)
    seizedBy[data.officer] = (seizedBy[data.officer] or 0) + data.count
    print(('Officer %d has logged %d tablets this session'):format(data.officer, seizedBy[data.officer]))
end)

AddEventHandler('playerDropped', function()
    seizedBy[source] = nil
end)

Price pills in your own selling script

-- Called from your sell handler with the pill's metadata and the buyer ped. The price is per
-- tablet, and a packed item prices as its loose line (PriceFor already weighs the packing).
local BASE_PRICE = { party = 30, capsule = 35, bar = 25, blues = 45, perc = 35 }

local function priceForPill(source, itemName, itemMetadata, buyerPed)
    local base = BASE_PRICE[(itemMetadata or {}).line] or 0
    local multiplier = exports['oxide-pills']:PriceFor(itemMetadata, { npcModel = GetEntityModel(buyerPed) })
    local price = math.floor(base * multiplier)

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

    -- Credit the sale to pill progression.
    exports['oxide-pills']:AddSold(source, 1)
    exports['oxide-pills']:AddXP(source, 3)
    return price
end

A custom selling script built this way prices pills the same way oxide-drugselling does, but it won't build brand reputation, add to a player's pills sold in line mastery, or move street sale goals. Only oxide-drugselling sales do those (and delivery drops, for reputation). Raising oxide-drugselling:drugSold from your own resource won't work: pills ignores the event unless oxide-drugselling raised it.

Read a setting from another resource

local delivery = exports['oxide-pills']:GetSetting('Delivery')
if delivery and delivery.enabled then
    print(('Pill delivery runs pay $%d per VELA 30'):format(delivery.perTablet.blues))
end

Next Steps