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:
- Add a WebP (preferred: every player downloads every icon) or PNG named after the key:
html/img/items/myems_medkit.webp, or the item'simagepath. If both exist, WebP wins. - Add
files { 'html/img/items/*.webp', 'html/img/items/*.png' }(or just the one you use) to yourfxmanifest.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:
| Return | Result |
|---|---|
true or nothing | One is used up (food, a bandage) |
false | Kept (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.
ammo = 0: equal.model = { 'adder', 't20' }: one of.ammo = { above = 0 }: alsobelow,atLeast,atMost.slots = { empty = false }: not nothing,false,'',0or an empty table.ammo = { below = 12, default = 0 }:defaultstands in for a missing field.
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- Keep your own default. Save your config's value for
defaultbefore you overwrite it, or the next registration declares the admin's value as the default. - Limits. Twenty;
name,descandweightare taken. A bad default or type refuses the item. - On a player's game it's
niluntil whip_core sends the values as they join; your hook runs then. - Saved in
whip_settings, history inwhip_settings_log.
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.
- When. At once from online players, open stashes, boots and the ground; elsewhere as each loads, bags and wallets included.
- Not touched: another resource's items (refused), and items in a fixed-shape panel (a magazine) or your own store kinds: yours to clear.
UnretireItem(key)frees the key again (register it to bring the item back); what was taken stays taken.
In game: /whip → Economy → ItemsServer owners#
Every item from every resource, searchable, with the ones an admin has changed. An item's page has:
- What it is, with Give to me and Edit hand position: how it's held out to give or throw, pose by pose (H next pose, R move or turn), plus
playerWalkandgrab. - Its settings: name, description, weight (for
config.lua's items also stacking, cooldown and kind) and its own, each with Reset. Apply saves for everyone (as Config does); only a permanent admin can. - What players see: its pictures and what shows each (pictures that change). Add picture takes a link from a site in Picture links accepted (Fivemanage by default).
Item definition#
The fields of a RegisterItem definition and of Config.Items.
| Field | Type | Description |
|---|---|---|
name | string | Required. Display name |
desc | string | Tooltip description |
weight | number | Required. kg per unit |
type | string | Category label: 'consumable', 'weapon', 'tool'… |
stack | boolean | Stacks in one slot |
maxStack | number | Units per stack: 1 if not stackable (more is refused), 100 if stackable and unset |
usable | boolean | Usable from the hotbar and right-click |
cooldown | number | Seconds between uses (0 = none) |
prop | string | Prop model when dropped |
grab | string | Picked up with '1h' (default) or '2h' (a rifle, a duffel bag) |
playerWalk | boolean | Held out to give or throw, the player keeps their own walk, not Config.GiveModeStyle. Default false |
metaFields | table[] | Card rows from metadata: { { key='plate', label='Plate' } }; a value shows when the key is missing |
fuelCapacity | number | Makes 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 |
defaultAction | string | Context menu action key (an item that opens a panel, say) |
contextOptions | table[] | { { action='open', label='Open', order=1 } }, with optional when, require, whyNot, anywhere. icon is ignored. See options that come and go |
groundOptions | table[] | Up to three: { { action, label, icon? } }. See options on the ground |
images, pictureFields | table[] | See pictures that change |
image | string | Icon path in your resource, if not html/img/items/<key>.webp or .png; '@resource/path' for another resource's. See Item icons |
settings | table[] | See Item settings |