Skip to content

Extra Configuration

The alcohol, drug and buff hooks in client/editable.lua.

On this page5

client/editable.lua is where you hook this resource into your own scripts. It sits outside the escrow alongside config.lua, so edit it freely. It holds the alcohol and drug state that breathalyzer and drug-testing scripts read back out through exports.

Client

The stock client/editable.lua, in full.

lua
Consumables = Consumables or {}
Consumables.Editable = Consumables.Editable or {}
 
local currentBacLevel = 0.0
 
function Consumables.Editable.OnAlcoholUpdate(level, type)
    local newBacLevel = 0.0
 
    if level > 0 then
        if type == 'heavy' then
            newBacLevel = math.min(level * 0.05, 0.40)
        elseif type == 'light' then
            newBacLevel = math.min(level * 0.02, 0.25)
        end
    end
 
    if newBacLevel ~= currentBacLevel then
        currentBacLevel = newBacLevel
    end
end
 
exports('GetBACLevel', function()
    return currentBacLevel
end)
 
exports('IsDrunk', function()
    return currentBacLevel > 0
end)
 
local activeDrugs = {}
 
function Consumables.Editable.OnDrugUpdate(bool, type)
    if bool then
        activeDrugs[type] = true
    else
        activeDrugs[type] = nil
    end
end
 
exports('GetHighDrug', function()
    local drugs = {}
    for k, _ in pairs(activeDrugs) do
        drugs[#drugs + 1] = k
    end
    return drugs
end)
 
exports('IsHigh', function()
    return next(activeDrugs) ~= nil
end)
 
exports('IsBuffActive', function(buffName)
    local buff = Consumables.ActiveBuffs and Consumables.ActiveBuffs[buffName]
    return buff ~= nil and GetGameTimer() < buff.expires
end)
 
exports('GetBuffDuration', function(buffName)
    local buff = Consumables.ActiveBuffs and Consumables.ActiveBuffs[buffName]
    return buff and buff.duration or 0
end)
 
exports('GetBuffRemaining', function(buffName)
    local buff = Consumables.ActiveBuffs and Consumables.ActiveBuffs[buffName]
    if not buff then return 0 end
    local remaining = (buff.expires - GetGameTimer()) / 1000
    return remaining > 0 and remaining or 0
end)
 
RegisterNetEvent('pixel-consumables:alcohol', function(itemName)
end)
 
RegisterNetEvent('pixel-consumables:drugs', function(itemName)
end)

OnAlcoholUpdate

Consumables.Editable.OnAlcoholUpdate(level, type) runs when an alcohol effect starts and again when it ends.

ArgumentNotes
levelDrinks counted since the last effect finished. The start call passes the current count, the end call passes 0
type'light' or 'heavy', matching which of the item's lightalcohol / heavyalcohol thresholds the count reached

Nothing is called while the count is still below lightalcohol. The stock body only stores the level as a BAC number; add your own call inside the if newBacLevel ~= currentBacLevel block to push it to a breathalyzer resource. The 0.40 and 0.25 caps are hardcoded here, not config.

OnDrugUpdate

Consumables.Editable.OnDrugUpdate(bool, type) runs when a drug effect starts and again when it ends.

ArgumentNotes
booltrue on start, false on end
typeThe effect name: psychedelic, brightpsychedelic, foggy, flicker, dizzy, shaking, hallucination or focus

An item with more than one entry in drugeffect calls this once per effect. For shaking and focus the false call fires immediately rather than when the effect ends, because both run on their own thread.

The true call happens before the effect is dispatched, and only the eight known effect names have a matching false call. Put an unrecognised name in drugeffect, a typo, or a custom effect of your own, and the hook fires true and never false, leaving IsHigh() stuck at true and the name stuck in GetHighDrug() until the player reconnects.

Exports

Call these from any other resource as exports['pixel-consumables']:GetBACLevel(). They are all client side; the resource defines no server exports.

ExportReturns
GetBACLevel()Current BAC as a number. 0.0 when sober
IsDrunk()true while BAC is above 0
GetHighDrug()Array of the drug effect names currently active
IsHigh()true while any drug effect is active
IsBuffActive(buffName)true while that buff is set and has not expired
GetBuffDuration(buffName)The duration the buff was applied with, in seconds. 0 when the buff is not set
GetBuffRemaining(buffName)Seconds left on the buff, never below 0

The three buff exports take one of nostress, stamina, strength, superjump, running, swimming, health, armor, energy.

Events you can hook

EventFires when
pixel-consumables:alcoholAn item with lightalcohol or heavyalcohol set is consumed
pixel-consumables:drugsAn item with drugeffect set is consumed

Both are triggered locally on the consuming player and pass the item name. They ship empty so you can fill them in. Configuration has a worked example using them.