Esc to clear, Enter to open the best match, click an export to open it in its page
Health & Status

Stats API

Server exports for stats and effects. New to stats? Read Stats & Effects first. The client's read-only GetStat, GetStats, HasEffect, GetEffects and OnStatChanged are on Player & Status (Client).

Stats

RegisterStat(name, config)SERVER#

Registers the stat name; a hud block puts a ring on every player's HUD as the call returns. The config is copied. Declare it in Whip.register: it's dropped when your resource stops, though values stay.

FieldTypeDescription
typestring?'need' or 'custom' (default). Vitals are WHIP's own; anything else is refused
defaultnumber?What a character starts on (default 0)
min / maxnumber?The range writes are clamped to (default 0–100)
persistboolean?Save with the character (default true). false: neither saved nor loaded, so it starts from default each login
decaynumber?Points added every decayInterval; negative drains. Omitted or 0: none
decayIntervalnumber?Seconds between decay ticks (default 10)
thresholdstable?Array of { stat, delta, value, below }: while past value (below = true for ≤, else ≥), add delta to stat each decay tick. Only on stats that decay
hudtable?{ color, icon, iconCritical, order, heartbeat, hideWhenEmpty, noCritical, showAboveZero, showBelowFull, glide }: see HUD Framework
Returns: boolean ok, string|nil err
Names are owned (the registration rule). health, armour, oxygen and another resource's stats are refused with the reason. Registering your own again is fine: the same definition changes nothing, a changed one replaces it.
GetStat(source, name) / GetStats(source)SERVER#

One stat, or a copy of all, from the server's cache. Reported combat damage lands here too, so health is current without reading the ped.

ParamTypeDescription
sourcenumberPlayer server ID
namestringStat name (GetStat only)
Returns: number|nil / table. With no character loaded, GetStat returns nil and GetStats {}, 'Player not loaded'
SetStat(source, name, value, reason?)SERVER#

Sets a stat, clamped to its range. The client gets it at once, and a persisting stat is queued for the next save. An unregistered name, such as a typo, is refused.

ParamTypeDescription
sourcenumberPlayer server ID
namestringA registered stat
valuenumberThe new value
reasonstring?What caused it ('quest reward'), for the debug change log and OnStatChanged. Default 'by <your resource>'
Returns: boolean ok, string|nil err: 'Player not loaded', 'no stat named "x" (RegisterStat it first)', 'value must be a number'
AddStat(source, name, delta, reason?)SERVER#

Adds delta to the current value (or the default when unset) and sets it as SetStat does.

ParamTypeDescription
sourcenumberPlayer server ID
namestringA registered stat
deltanumberAmount to add; negative subtracts
reasonstring?As for SetStat ('item:food')
Returns: boolean ok, string|nil err: as SetStat, or 'amount must be a number'
OnStatChanged(name, callback, id?, opts?)SERVER#

Calls you when any player's stat changes, by any path. Declare it in Whip.register: it's keyed by your resource and id, so running it again replaces it, and it goes when your resource stops.

ParamTypeDescription
namestringA stat name, or '*' for every stat
callbackfunction(source, value, old, reason), or (source, name, value, old, reason) for '*'. reason: 'decay', 'item:food', 'combat (reported): Pistol', 'by my_resource'
idany?Only to hold two listeners on one stat (the options may go here instead)
optstable?table = true: one table { source, key, value, old, reason }. now = true: also called straight away for every loaded player with the stat (old = nil, reason = 'now')
Returns: boolean ok, string|nil err
Clamping can't loop. A listener that sets its own stat isn't called again for that change; the value still lands.

Effects

ApplyEffect(source, name, config)SERVER#

Applies a timed effect to a player. It's your resource's: removed without onRemove when your resource stops (a resource field is ignored). Ticks pause while dead and during the spawn guard.

FieldTypeDescription
durationnumber?Seconds until removed. nil: until RemoveEffect
magnitudenumber?Any value your callbacks read (default 1)
tickRatenumber?Seconds between onTick calls (default 1)
onTick / onApply / onRemovefunction?(source, player, effect). onRemove also runs on logout or disconnect (effect.reason 'logout' / 'disconnect')
damageModifier / meleeModifiernumber?Incoming damage multiplier: 0.5 takes half
replaceSilentlyboolean?On replacing an active effect of this name, skip its onRemove (default: it runs)
sheet'light'?Callbacks get the light player sheet (who, whether dead), not the full one, which reads the ped, pockets and two stats each tick
Returns: boolean ok, string|nil err: 'duration must be a positive number of seconds, or nil', 'Player not loaded'...
Nothing stacks. A second apply under the same name replaces the effect entirely. To stack, read GetEffects and apply the sum. stackable is refused.
RemoveEffect(source, name)SERVER#

Removes an effect early: runs its onRemove, recalculates the damage modifiers if it carried one and tells the client. Any resource may remove any effect.

ParamTypeDescription
sourcenumberPlayer server ID
namestringThe name it was applied under
Returns: boolean ok, string|nil err: 'no effect named "x" on this player'
HasEffect(source, name) / GetEffects(source)SERVER#

Whether an effect is active, and every active one keyed by name: duration, remaining, magnitude, tickRate, damageModifier, meleeModifier, resource. No callbacks.

ParamTypeDescription
sourcenumberPlayer server ID
namestringEffect name (HasEffect only)
Returns: boolean / table: { [name] = effect }, empty when none
GetDamageModifier(source) / GetMeleeModifier(source)SERVER#

The combined, clamped incoming weapon (or melee) multiplier from every active effect, for your own damage math.

ParamTypeDescription
sourcenumberPlayer server ID
Returns: number: 1.0 with no modifier
-- A trap that respects armour buffs
exports.whip_core:AddStat(source, 'health', -25 * exports.whip_core:GetDamageModifier(source))