Inventory API (client)
Client exports for the player's own items and hands, item flags for your prompts, and replacing the inventory screen. The server's are on Inventory API.
Reading
Whether the player has an item, in either pocket.
| Param | Type | Description |
|---|---|---|
| itemKey | string | Item key |
| filter | function|number? | function(metadata) → bool, or a minimum count (HasItem('bandage', 3)) |
boollocal hasGoldPick = exports.whip_core:HasItem('lockpick', function(meta) return meta and meta.tier == 'gold' end)
How many of an item the player has, across every pocket.
| Param | Type | Description |
|---|---|---|
| itemKey | string | Item key |
| filter | function? | function(metadata) → bool. A number is ignored: use HasItem(item, 5) for "at least 5" |
number (0 if none)local keys = exports.whip_core:GetItemCount('vehicle_key', function(meta) return meta and meta.vehicleId == vehicleId end)
What the player holds, as the server last said (SetHeldItem). No metadata: that's the server's GetHeldItem(source). For a prompt about one held thing, require = { held = 'jerry_can' } is cheaper: your canInteract isn't asked while the hand holds anything else.
{ item, pocket, slot } (a copy) or nilWhether the plain inventory screen is open. To ask whether the player is busy, use IsGameInputFree (Screens, input and controls).
boolBlock inventory opening for this resource and close an open inventory when locking. false releases only your resource's lock; other resource locks and the database lock still apply. Your lock is cleared when your resource stops. This is a client UI lock, not server authorization for inventory writes.
| Param | Type | Description |
|---|---|---|
| locked | boolean | true to lock, false to release |
boolean accepted; false for a non-boolean or no calling resourceCloses the inventory screen, with any open container, vehicle storage or panel.
Hands
Call it before putting something in the player's hands (a phone, a tool, a box): whatever they hold is put away first, through the 'freeHands' hook (whip_gunny holsters with its animation). It waits, so call it from a thread, through Whip.core.
true when the hands are free, false while a weapon is still in them, or false, words while they're blockedlocal free, why = Whip.core:FreeHands()
if not free then return end
Whip.core:PlayEmote('clipboard')
Stops the player using their hands, with words they're shown: everything (tied up, a cutscene) or weapons only (a hospital). A block of everything empties the hands at once, and FreeHands returns false while it lasts, so the phone, a tool or give mode won't start. Every block holsters a gun and stops a draw. Yours go when your resource stops; for one player from the server, see the server's.
| Param | Type | Description |
|---|---|---|
| id | string | Your name for it; the same id replaces |
| opts | table? | label: the words shown; only = 'weapons'. Without only: everything |
true, or false, reason (no id, a bad only or label; UnblockHands: none of yours by that id)AddEventHandler('whip_core:zone:entered', function(e)
if e.key == 'pillbox' then
exports.whip_core:BlockHands('pillbox', { only = 'weapons', label = 'No weapons in the hospital' })
end
end)
AddEventHandler('whip_core:zone:exited', function(e)
if e.key == 'pillbox' then exports.whip_core:UnblockHands('pillbox') end
end)
Whether this game's blocks or the server's block the hands: 'weapon' for a draw (any block), nothing for anything in the hands (a block of everything). Listen for whip_core:hands:blocked to put away what you hold.
true, words, or falselocal blocked, why = exports.whip_core:AreHandsBlocked('weapon')
if blocked then exports.whip_core:Notify(why, 'error') return end
Runs your code at a moment in the client inventory flow. A handler may return a delay in ms; whip_core waits for the longest.
| Param | Type | Description |
|---|---|---|
| hookName | string | 'beforeGiveMode', 'beforePlaceMode' (placing an item or an emote) or 'freeHands' (something needs the hands, such as the phone: put away what you hold) |
| handler | function | May return a delay in ms |
| id | string? | To hold two handlers on one hook; the same id replaces |
true, or false, reason: no handler, or an unknown hookexports.whip_core:RegisterClientHook('beforeGiveMode', function()
if MyWeaponEquipped() then Holster() return 200 end -- WHIP waits 200 ms
end)
How a player moves while holding an item out to give it. The default is Config.GiveModeStyle (the Trash walk, no faster than a jog); the latest resource's wins while it runs, and yours goes when it stops. An item with playerWalk keeps their own walk.
| Param | Type | Description |
|---|---|---|
| style | table|nil | walk: a /walk name or clipset; speed: 'jog' (no sprint) or 'walk' (no running). nil clears yours |
true, or false, reasonItem flags#
A flag says whether the player carries an item, read from a cache kept up to date on every inventory change. Use one in canInteract when the rule is about metadata (a charged battery, a key for this car); for a plain "carries one", require = { item = 'crowbar' } is enough.
Registers a flag; declare it in Whip.register. Yours go when your resource stops; a filter that errors counts as "no" and is reported once in F8.
| Param | Type | Description |
|---|---|---|
| flagName | string | Your name for it; also the item key unless itemOrFilter names one |
| itemOrFilter | string|function? | The item key, or a metadata filter |
| filter | function? | function(metadata) → bool, when itemOrFilter is a key |
true, or false, reason: a name that isn't a string, or a flag name another resource holds (whip_core's lockpick included)exports.whip_core:RegisterItemFlag('my_valet_key', 'vehicle_key', function(meta)
return meta and meta.plate == 'ABC123'
end)
Whether the player has the flag's item now.
| Param | Type | Description |
|---|---|---|
| flagName | string | The name you registered |
boolWhip.register(function()
Whip.core:RegisterItemFlag('my_crowbar', 'crowbar')
Whip.core:AddAction({
id = 'crowbar', at = { vehiclePart = 'door_dside_f' }, label = 'Pry Open',
canInteract = function(ctx)
return exports.whip_core:HasItemFlag('my_crowbar') and GetVehicleDoorLockStatus(ctx.entity) == 2
end,
onSelect = function(ctx) TriggerServerEvent('my_resource:pry', VehToNet(ctx.entity)) end,
})
end)Replacing the inventory UI#
To restyle the inventory or draw a different screen, set Config.InventoryRenderer to your resource. It draws, and WHIP keeps running the inventory: your UI needs one function, render(), and each move is one call, checked like WHIP's own. Nothing in whip_core is edited, so it survives updates.
- Build it in Chrome with sample items:
node whip_core/dev/inventory-preview/preview.js my_inventory_ui(reloads on save). - Try it in game:
/whip_inventory_ui my_inventory_ui(developer mode).
The contract is in whip_core/docs/nui-inventory.md. Config.EnableInventoryUI = false is only for a server with no inventory screen at all.
The player's whole inventory, for drawing your own UI, as a deep copy.
{ [container] = { [slot] = { item, amount, metadata } } }, or {}, 'Player not loaded' before the first sync