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

Stats & Effects

Stats are a character's numbers: health, armour, hunger, thirst, oxygen, and any you register, such as stress or reputation. Effects are timed changes on top of them: a poison, a heal over time, a damage buff. WHIP saves and syncs them, so you write no table, save code or HUD.

Built-in stats

Every stat lives on the server and the player's game follows it, except combat damage: the hurt player's game sees the hit first and reports it, so a shot lands without waiting.

StatTypeRangeDecayThreshold
healthvital0–200——
armourvital0–100——
hungerneed0–100empty in Config.HungerMinutes (120)≤10 → health -1
thirstneed0–100empty in Config.ThirstMinutes (90)≤10 → health -1
oxygencustom0–100drains under water, refills above0 → drowns

Vital stats are synced to the GTA ped. Needs decay on the server, and their thresholds can damage other stats. Custom stats are yours (stress, tiredness).

Hunger and thirst are on by default: 100 is full, 0 is starving, and at 10 or below each costs 1 health per decay tick. Config.Hunger / Config.Thirst turn one off (also in /whip → Settings → Config → Hunger, thirst and breath). One that's off has no gauge, doesn't drain or save, and reads 100, so food and drink still work. Config.StatOrder sets the gauges' order.

Registering a stat

Declare RegisterStat from your server code, in Whip.register (why). Decay, thresholds, saving and client sync come with it. A hud block draws a ring on every player's HUD (HUD Framework); leave it out for a server-only stat such as reputation.

Whip.register(function()
    Whip.core:RegisterStat('stress', {
        type = 'custom',
        default = 0, min = 0, max = 100,
        persist = true,
        decay = -0.5,          -- eases off half a point...
        decayInterval = 15,    -- ...every 15 seconds
        hud = { icon = 'M12 2C6.48 2 2 6.48 2 12...', color = '#e879f9', order = 5 },
    })
end)

Reading and changing stats

Change stats on the server; the player's game follows. The client can only read.

-- server
local hunger = exports.whip_core:GetStat(source, 'hunger')
exports.whip_core:SetStat(source, 'hunger', 100)              -- full
exports.whip_core:AddStat(source, 'hunger', 25, 'quest reward')  -- restore 25
local all = exports.whip_core:GetStats(source)             -- { health = 200, hunger = 74, ... }

-- client
local hunger = exports.whip_core:GetStat('hunger')

The setters return true, or false and a reason: an unregistered name is refused. The optional last reason shows in the debug change log and is passed to OnStatChanged.

A consumable item

The item's use handler calls AddStat. Return its refusal and the player keeps the item. whip_core's own food item (server/items/food.lua) works this way.

-- after RegisterItem('mycafe_sandwich', { type = 'consumable', usable = true, ... })
Whip.register(function()
    Whip.core:RegisterUseHandler('mycafe_sandwich', function(source, player, slotData)
        local ok, why = exports.whip_core:AddStat(source, 'hunger', 25, 'item:sandwich')
        if not ok then return false, why end   -- refused: they keep it
        return true                            -- consume one
    end)
end)

Listening for changes

OnStatChanged works on both sides and hears every change: decay, items, effects, combat damage and other resources' writes. On the server the callback gets the player's source first and the reason last. Declare it in Whip.register: running it again replaces it, and it goes when your resource stops.

-- server: every player
exports.whip_core:OnStatChanged('hunger', function(source, value, old, reason)
    if value <= 0 then --[[ starving ]] end
end)

-- client: the local player. old is nil for the first value after login.
exports.whip_core:OnStatChanged('reputation', function(value, old)
    if old and value >= 100 and old < 100 then
        exports.whip_core:Notify('Reputation: Trusted! New routes unlocked.', 'success')
    end
end)

Listen to '*' for every stat; the callback then gets the stat's name before the value. Options take one table instead of arguments (table = true) and a first call with the current value (now = true).

Effects

An effect runs your callbacks on a timer and removes itself when its duration runs out. It moves no stat by itself: the heal below is its onTick calling AddStat. Use one when a change must expire and clean up on its own; for a one-off change, call AddStat.

-- A bandage: 5 health every second for 10 seconds
exports.whip_core:ApplyEffect(source, 'healing', {
    duration = 10,      -- seconds; nil = until RemoveEffect
    magnitude = 5,      -- any number your callbacks read
    tickRate = 1,       -- seconds between onTick calls
    onTick = function(src, player, effect)
        exports.whip_core:AddStat(src, 'health', effect.magnitude)
    end,
    onRemove = function(src)
        exports.whip_core:NotifyPlayer(src, 'Healed!', 'success')
    end,
})

Any resource can end one early with RemoveEffect(source, 'healing'). Applying an active name replaces it: nothing stacks. Every field is on the ApplyEffect card.

Damage modifiers

Give an effect damageModifier (weapons) or meleeModifier to scale the damage the player takes: 0.5 takes half, 2.0 double. No other export or client code is needed. whip_core's own damage_reducer item (server/items/damage_reducer.lua) is a complete example.

-- In an item's use handler: half weapon damage for 20 seconds
return exports.whip_core:ApplyEffect(source, 'mydoc_iron_tonic', {
    duration = 20,
    damageModifier = 0.5,
    onRemove = function(src) exports.whip_core:NotifyPlayer(src, 'Damage reduction wore off', 'warning') end,
})

Good to know

Hit causes are reported, not proven. The debug log's combat (reported): Carbine Rifle by John Smith (#3) comes from the hurt player's own game, so a modified game can make it say anything: never decide anything from it. For who killed a player, use killer on the server's whip_core:player:died (Death & Revive).