Studios
Buffshouse-3.jpg

Examples

SoonBuffsQbox
PAGE 04 OF 06  ·  CONFIGURATION → EXAMPLES → TROUBLESHOOTINGdocs.glitchstudios.dev
Browse docs

Hooking a consumables script#

Coffee and energy drinks work on their own when no consumables resource is installed (Config.Caffeine.registerItems = 'auto'). If you run a consumables script, 'auto' leaves the items to it. Either set registerItems = true or add these hooks to your script.

-- server: when an alcoholic drink is used
pcall(function() exports['glitch-buffs']:Drank(source) end)

-- server: when a coffee or energy drink is used
pcall(function() exports['glitch-buffs']:Caffeine(source, itemName) end)

-- client: when the player is sober again. peak is the highest drunk level reached
TriggerServerEvent('glitch-buffs:server:sober', peak)

A hangover needs both parts: at least Config.Hangover.drinks calls to Drank inside Config.Hangover.window, and a sober report with a peak of at least Config.Hangover.heavyLevel.

Register coffee and energy drinks here#

Config.Caffeine.registerItems = true

Adding a new effect#

Add the effect to Config.Effects, then start it from your own script.

-- config/main.lua
Config.Effects.focus = {
    kind = 'buff', label = 'Focus', icon = 'ti-coffee', duration = 120,
    up = { 'Stamina recovers faster' },
    stamina = { regen = 0.04 },
}
-- server
exports['glitch-buffs']:Apply(source, 'focus')
exports['glitch-buffs']:Apply(source, 'focus', { duration = 60 })

An icon that is not in html/fonts/tabler-subset.css shows blank, so reuse an icon that ships or add yours to the subset.

Drug scripts and tolerance#

Call DrugUse before the high starts, scale the dose by share and stop if overdose is true.

local tol = exports['glitch-buffs']:DrugUse(source, 'cocaine', 120)
if tol.overdose then return end
local seconds = math.floor(120 * tol.share)

Add the drug name to Config.Tolerance.noOverdose if it should get weaker but never overdose. An optional fourth argument such as { comedownMult = 0.5 } shortens the comedown (clamped between 0.1 and 1).

Job scripts and fatigue#

-- one pallet loaded, using the trucker rate from Config.Fatigue.jobs
exports['glitch-buffs']:AddFatigue(source, 'trucker')

-- ten units of mining
exports['glitch-buffs']:AddFatigue(source, 'mining', 10)

-- a flat number of points
exports['glitch-buffs']:AddFatigue(source, 3)

Add your own work types under Config.Fatigue.jobs.

Protein and checks#

exports['glitch-buffs']:Protein(source, 600)

if exports['glitch-buffs']:Has(source, 'infection') then
    exports['glitch-buffs']:Remove(source, 'infection', 'treated')
end

Medical resource hook#

Call Treated from your hospital script so a check-in cures infection and any revive ends adrenaline.

exports['glitch-buffs']:Treated(source, 'hospital')

What the server decides#

Timers, item use, medical checks and tolerance run on the server. Item uses lock per player, check again that the player is still around after each client answer, and take the item from the slot that was used. Stamina changes, sedated movement and steroid damage run on the client, so treat them as a soft system.