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

Items

An item is a key and a definition: a name, a weight and whatever else it needs. Your resource registers its own items and gives them a use, right-click options, pictures and settings an admin can change.

Registering an item

whip_core's own items are in Config.Items. Register yours with RegisterItem; every field is under Item definition below.

-- server.lua (fxmanifest.lua: shared_script '@whip_core/lib/satellite.lua')
Whip.register(function()
    Whip.core:RegisterItem('myems_medkit', {
        name = 'Medical Kit', desc = 'Heals injuries', weight = 0.5, type = 'medical',
        stack = true, maxStack = 5, usable = true, cooldown = 10, prop = 'prop_ld_health_pack',
    })
end)

It works everywhere at once.

Item icons#

Your item's picture lives in your resource:

  1. Add a WebP (preferred: every player downloads every icon) or PNG named after the key: html/img/items/myems_medkit.webp, or the item's image path. If both exist, WebP wins.
  2. Add files { 'html/img/items/*.webp', 'html/img/items/*.png' } (or just the one you use) to your fxmanifest.lua. Without it the inventory shows the "missing" picture.

A new picture shows after its resource restarts. whip_autos is a good one to copy.

Stacking

An item with stack = true and maxStack above 1 stacks in one slot. Adding tops up existing stacks first (lowest slot first), then fills empty slots; removing empties the highest slots first. Cash has maxStack = 999999 and weighs 0.0001 kg a note.

Using an item

When a player uses a usable item, the server checks it exists and is off cooldown, then calls your use handler. Its return decides the rest:

ReturnResult
true or nothingOne is used up (food, a bandage)
falseKept (a tool, a toggle). Still a use: the cooldown starts and whip_core:item:used fires
false, 'why'Refused: kept, no cooldown, no event, no use logged, and the player sees why. Use this for "not now"
exports.whip_core:RegisterUseHandler('myems_medkit', function(source, player, slotData, addr)
    local ok, why = exports.whip_core:SetStat(source, 'health', 200, 'item:medkit')
    if not ok then return false, why end
    return true
end)

addr is the item's address, for SetItemMetadata and the store calls. For a use at the end of a progress bar (a drink, a car part), pass a table instead: see a use with a progress bar.

Right-click options

An item's defaultAction and contextOptions add options to its menu, under Use; Give, Place, Split and Destroy go below. Lowest order goes first, then options without one, as listed. Each action needs a handler from RegisterContextAction, named with your resource's prefix.

contextOptions = { { action = 'my_resource:inspect_serial', label = 'Inspect serial', order = 1 } },   -- the definition

exports.whip_core:RegisterContextAction('my_resource:inspect_serial', function(source, player, slotData, addr)
    local serial = slotData.metadata and slotData.metadata.serial
    if not serial then return false, 'No serial' end   -- refused: the player sees why
    exports.whip_core:NotifyPlayer(source, 'Serial: ' .. serial)
end)

To add an option to another resource's item (police "Check for prints" on whip_gunny's guns), use AddItemOption.

Options that come and go#

when tests the item's metadata; require tests the player, with an interaction's require words (job, onDuty, jobPermission, item, zone, charId, ace, vehicle, alive). A failing option is left off the menu, and the server checks both again before it runs.

{ action = 'my_guns:unload', label = 'Unload', when = { ammo = { above = 0 } } },
{ action = 'my_cops:prints', label = 'Check for prints', require = { job = 'police', onDuty = true } },

Every test in a when must pass; unknown words are refused at registration.

A double-click or hotbar key on a failing option shows whyNot ('Magazine is full'), or "Load Bullets isn't possible right now".

Options outside the pockets#

Options show only while the player carries the item. anywhere = true also offers one in a boot, glovebox, stash, bag, wallet or panel the player has open (not on the ground, in an ignition or on a shop's shelf). The handler's addr is then that store's, such as { kind = 'vehicle', id, sub = 'trunk', slot }, so handle any address.

Options on the ground#

A pile's 3D prompt says Pick up. groundOptions adds up to three of the item's own options: the item is picked up, then the option runs on its new slot, with the usual checks (a refusal leaves it on the ground). whip_gunny's weapons offer Equip.

groundOptions = { { action = 'whip_gunny:equip_weapon', label = 'Equip', icon = 'target' } },   -- "Equip Pump Shotgun"

label comes before the item's name (24 letters at most); icon is a glyph from html/js/glyphs.js.

Pictures that change#

An item's images list gives it other pictures for other states: the first whose when passes is drawn, otherwise its own. Paths are inside your resource, and {field} is filled from metadata.

images = { { when = { slots = { empty = false } }, image = 'html/img/items/duffle_bag_full.webp' } }
images = { { image = 'html/img/items/keys/{make}.webp' } }   -- {make}: the maker of the car its model names
images = {                                                   -- by the slot's count, as WHIP's cash does
    { amount = { below = 100 },  image = 'html/img/items/coins_few.webp' },
    { amount = { atLeast = 100 }, image = 'html/img/items/coins_heap.webp' },
}

amount takes above, below, atLeast, atMost. With no slot to count (a shop's list) none fits, so the item's own image should suit any amount. A missing file shows the item's own picture.

Admins can change these on the Items page, choosing by count, metaFields, fields your pictures test, and pictureFields: { { key = 'mustard', label = 'Mustard', type = 'bool' } }, where type is 'bool', 'number' or 'text' (the default).

Item settings#

Admins can change any item's name, description and weight on the Items page; your definition is the default, and an admin's change stays until Reset.

An item can declare its own settings too (a magazine's size, a gun's reload time), shown on its Items page. Each entry in its settings list is a setting entry: key, type ('int', 'number', 'bool', 'string' or 'enum'), default, label, and the min, max, step, unit, maxLen, nullable, options or help its type takes.

Whip.register(function()
    Whip.core:RegisterItem('my_guns_mag', {
        name = 'Pistol Magazine', weight = 0.2, stack = false,
        settings = {
            { key = 'capacity', type = 'int', min = 1, max = 100, default = 12, label = 'Rounds it holds' },
        },
    })
    Whip.core:OnItemSettingChanged('my_guns_mag', 'capacity', function(value, old)
        Config.Magazines.my_guns_mag.capacity = value   -- at once, on server and clients; Reset too
    end)
end)
local capacity = exports.whip_core:GetItemSetting('my_guns_mag', 'capacity')   -- server or client

Retiring an item

RetireItem(key, reason) takes one of your own items out of the game for good: RetireItem('mycafe_bagel', 'Bagels are off the menu'). Its definition goes, none can be made, and every one is taken away, logged as lost with your reason, not refunded. It returns true, or false and a reason.

In game: /whip → Economy → ItemsServer owners#

Every item from every resource, searchable, with the ones an admin has changed. An item's page has:

Item definition#

The fields of a RegisterItem definition and of Config.Items.

FieldTypeDescription
namestringRequired. Display name
descstringTooltip description
weightnumberRequired. kg per unit
typestringCategory label: 'consumable', 'weapon', 'tool'…
stackbooleanStacks in one slot
maxStacknumberUnits per stack: 1 if not stackable (more is refused), 100 if stackable and unset
usablebooleanUsable from the hotbar and right-click
cooldownnumberSeconds between uses (0 = none)
propstringProp model when dropped
grabstringPicked up with '1h' (default) or '2h' (a rifle, a duffel bag)
playerWalkbooleanHeld out to give or throw, the player keeps their own walk, not Config.GiveModeStyle. Default false
metaFieldstable[]Card rows from metadata: { { key='plate', label='Plate' } }; a value shows when the key is missing
fuelCapacitynumberMakes it a fuel can: how much of a car's tank (100) a full one holds, so 30 is 30%. Metadata fuel is how full it is, 0-100. Held (SetHeldItem), whip_fuel fills it at a pump and refuels cars from it. whip_gunny's jerry_can is one
defaultActionstringContext menu action key (an item that opens a panel, say)
contextOptionstable[]{ { action='open', label='Open', order=1 } }, with optional when, require, whyNot, anywhere. icon is ignored. See options that come and go
groundOptionstable[]Up to three: { { action, label, icon? } }. See options on the ground
images, pictureFieldstable[]See pictures that change
imagestringIcon path in your resource, if not html/img/items/<key>.webp or .png; '@resource/path' for another resource's. See Item icons
settingstable[]See Item settings