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

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

HasItem(itemKey, [filter])CLIENT#

Whether the player has an item, in either pocket.

ParamTypeDescription
itemKeystringItem key
filterfunction|number?function(metadata) → bool, or a minimum count (HasItem('bandage', 3))
Returns: bool
local hasGoldPick = exports.whip_core:HasItem('lockpick', function(meta) return meta and meta.tier == 'gold' end)
GetItemCount(itemKey, [filter])CLIENT#

How many of an item the player has, across every pocket.

ParamTypeDescription
itemKeystringItem key
filterfunction?function(metadata) → bool. A number is ignored: use HasItem(item, 5) for "at least 5"
Returns: number (0 if none)
local keys = exports.whip_core:GetItemCount('vehicle_key', function(meta) return meta and meta.vehicleId == vehicleId end)
GetHeldItem()CLIENT#

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.

Returns: { item, pocket, slot } (a copy) or nil
IsInventoryOpen()CLIENT#

Whether the plain inventory screen is open. To ask whether the player is busy, use IsGameInputFree (Screens, input and controls).

Returns: bool
SetInventoryLocked(locked)CLIENT#

Block 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.

ParamTypeDescription
lockedbooleantrue to lock, false to release
Returns: boolean accepted; false for a non-boolean or no calling resource
CloseInventory()CLIENT#

Closes the inventory screen, with any open container, vehicle storage or panel.

Hands

FreeHands()CLIENTWAITS#

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.

Returns: true when the hands are free, false while a weapon is still in them, or false, words while they're blocked
local free, why = Whip.core:FreeHands()
if not free then return end
Whip.core:PlayEmote('clipboard')
BlockHands(id, opts) / UnblockHands(id)CLIENT#

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.

ParamTypeDescription
idstringYour name for it; the same id replaces
optstable?label: the words shown; only = 'weapons'. Without only: everything
Returns: 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)
AreHandsBlocked(what)CLIENT#

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.

Returns: true, words, or false
local blocked, why = exports.whip_core:AreHandsBlocked('weapon')
if blocked then exports.whip_core:Notify(why, 'error') return end
RegisterClientHook(hookName, handler, id?)CLIENT#

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.

ParamTypeDescription
hookNamestring'beforeGiveMode', 'beforePlaceMode' (placing an item or an emote) or 'freeHands' (something needs the hands, such as the phone: put away what you hold)
handlerfunctionMay return a delay in ms
idstring?To hold two handlers on one hook; the same id replaces
Returns: true, or false, reason: no handler, or an unknown hook
exports.whip_core:RegisterClientHook('beforeGiveMode', function()
    if MyWeaponEquipped() then Holster() return 200 end   -- WHIP waits 200 ms
end)
SetGiveModeStyle(style)CLIENT#

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.

ParamTypeDescription
styletable|nilwalk: a /walk name or clipset; speed: 'jog' (no sprint) or 'walk' (no running). nil clears yours
Returns: true, or false, reason

Item 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.

RegisterItemFlag(flagName, [itemOrFilter], [filter])CLIENT#

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.

ParamTypeDescription
flagNamestringYour name for it; also the item key unless itemOrFilter names one
itemOrFilterstring|function?The item key, or a metadata filter
filterfunction?function(metadata) → bool, when itemOrFilter is a key
Returns: 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)
HasItemFlag(flagName)CLIENT#

Whether the player has the flag's item now.

ParamTypeDescription
flagNamestringThe name you registered
Returns: bool
Whip.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.

  1. Build it in Chrome with sample items: node whip_core/dev/inventory-preview/preview.js my_inventory_ui (reloads on save).
  2. 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.

GetInventory()CLIENT#

The player's whole inventory, for drawing your own UI, as a deep copy.

Returns: { [container] = { [slot] = { item, amount, metadata } } }, or {}, 'Player not loaded' before the first sync