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
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.
| Field | Type | Description |
|---|---|---|
| type | string? | 'need' or 'custom' (default). Vitals are WHIP's own; anything else is refused |
| default | number? | What a character starts on (default 0) |
| min / max | number? | The range writes are clamped to (default 0–100) |
| persist | boolean? | Save with the character (default true). false: neither saved nor loaded, so it starts from default each login |
| decay | number? | Points added every decayInterval; negative drains. Omitted or 0: none |
| decayInterval | number? | Seconds between decay ticks (default 10) |
| thresholds | table? | 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 |
| hud | table? | { color, icon, iconCritical, order, heartbeat, hideWhenEmpty, noCritical, showAboveZero, showBelowFull, glide }: see HUD Framework |
boolean ok, string|nil errhealth, 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.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.
| Param | Type | Description |
|---|---|---|
| source | number | Player server ID |
| name | string | Stat name (GetStat only) |
number|nil / table. With no character loaded, GetStat returns nil and GetStats {}, 'Player not loaded'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.
| Param | Type | Description |
|---|---|---|
| source | number | Player server ID |
| name | string | A registered stat |
| value | number | The new value |
| reason | string? | What caused it ('quest reward'), for the debug change log and OnStatChanged. Default 'by <your resource>' |
boolean ok, string|nil err: 'Player not loaded', 'no stat named "x" (RegisterStat it first)', 'value must be a number'Adds delta to the current value (or the default when unset) and sets it as SetStat does.
| Param | Type | Description |
|---|---|---|
| source | number | Player server ID |
| name | string | A registered stat |
| delta | number | Amount to add; negative subtracts |
| reason | string? | As for SetStat ('item:food') |
boolean ok, string|nil err: as SetStat, or 'amount must be a number'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.
| Param | Type | Description |
|---|---|---|
| name | string | A stat name, or '*' for every stat |
| callback | function | (source, value, old, reason), or (source, name, value, old, reason) for '*'. reason: 'decay', 'item:food', 'combat (reported): Pistol', 'by my_resource' |
| id | any? | Only to hold two listeners on one stat (the options may go here instead) |
| opts | table? | 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') |
boolean ok, string|nil errEffects
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.
| Field | Type | Description |
|---|---|---|
| duration | number? | Seconds until removed. nil: until RemoveEffect |
| magnitude | number? | Any value your callbacks read (default 1) |
| tickRate | number? | Seconds between onTick calls (default 1) |
| onTick / onApply / onRemove | function? | (source, player, effect). onRemove also runs on logout or disconnect (effect.reason 'logout' / 'disconnect') |
| damageModifier / meleeModifier | number? | Incoming damage multiplier: 0.5 takes half |
| replaceSilently | boolean? | 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 |
boolean ok, string|nil err: 'duration must be a positive number of seconds, or nil', 'Player not loaded'...GetEffects and apply the sum. stackable is refused.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.
| Param | Type | Description |
|---|---|---|
| source | number | Player server ID |
| name | string | The name it was applied under |
boolean ok, string|nil err: 'no effect named "x" on this player'Whether an effect is active, and every active one keyed by name: duration, remaining, magnitude, tickRate, damageModifier, meleeModifier, resource. No callbacks.
| Param | Type | Description |
|---|---|---|
| source | number | Player server ID |
| name | string | Effect name (HasEffect only) |
boolean / table: { [name] = effect }, empty when noneThe combined, clamped incoming weapon (or melee) multiplier from every active effect, for your own damage math.
| Param | Type | Description |
|---|---|---|
| source | number | Player server ID |
number: 1.0 with no modifier-- A trap that respects armour buffs
exports.whip_core:AddStat(source, 'health', -25 * exports.whip_core:GetDamageModifier(source))