Inventory
A server-only inventory bridge for VORP and RSG. Use it when a resource needs item counts, carry checks, adds, or removes without knowing which framework is running underneath.
Returns how many of an item the player has. Invalid inputs, missing inventory resources, or unsupported frameworks return 0.
| Param | Type | Description |
|---|---|---|
| source | integer | Player server ID. |
| item | string | Inventory item name. |
| metadata | table | nil | Optional metadata filter where supported. |
local count = wc:GetItemCount(source, 'corn')Returns true only when the player can receive that item amount.
Invalid source, blank item names, zero/negative/NaN amounts, missing inventory exports, and full inventories return false.
Adds an item after validation and a carry check.
| Returns | Description |
|---|---|
| boolean, string | nil | true on success, otherwise false, errorCode. |
local ok, err = wc:AddItem(source, 'delivery_token', 1)
if not ok then
print('Could not add item:', err)
endRemoves items only when the player has enough. SubItem is an alias.
local ok, err = wc:RemoveItem(source, itemName, quantity)
if not ok then return false, err endBoolean helper for GetItemCount(source, item, metadata) >= amount. Amount defaults to 1.
Supported Frameworks
| Framework | Inventory path | Notes |
|---|---|---|
| VORP | vorp_inventory | Uses getItemCount, canCarryItem, addItem, and subItem/removeItem. |
| RSG | rsg-core player functions | Uses GetItemByName, AddItem, and RemoveItem. If an RSG inventory exposes CanAddItem, the bridge uses it for carry checks. |
Error Codes
AddItem and RemoveItem return stable error strings: invalid_source, invalid_item, invalid_amount, framework_not_supported, inventory_unavailable, not_enough_items, and cannot_carry.
Migration
if invGetItemCount(source, itemName) < qty then return end
invSubItem(source, itemName, qty)if wc:GetItemCount(source, itemName) < qty then return end
wc:RemoveItem(source, itemName, qty)Metadata
The metadata parameter is optional. VORP receives a metadata table when supported. RSG receives metadata as the item info table for adds/removes. Inventory builds vary, so resources should treat metadata filtering as best effort unless their server inventory is known to support it.
Real Wild County example — corn delivery sack turn-in
wc_corndelivery checks the player is actually carrying the delivery sack before paying out, and removes it server-side so nothing can be turned in twice.
RegisterNetEvent('wc_corndelivery:turnIn', function()
local src = source
if not wc:HasItem(src, 'corn_sack', 1) then
wc:Notify(src, { variant = 'fail', title = "You don't have the sack." })
return
end
local ok = wc:RemoveItem(src, 'corn_sack', 1)
if not ok then return end -- inventory rejected the removal, don't pay out
wc:AddMoney(src, 35, 0)
wc:WcNotify(src, 'Corn delivered — +$35', 'SUCCESS')
end)
Common mistakes
- Calling these exports from client code — the whole module is server-only. Verify inventory state via a client→server event or callback instead.
- Paying a reward before confirming
RemoveItemactually succeeded — always check the boolean return first. - Skipping
HasItem/CanCarryItemand lettingAddItem/RemoveItemsilently fail without telling the player why. - Trusting a client-sent item name or amount for a sell/turn-in flow — always validate against your own server-side price/item table.
Security notes
Troubleshooting
- If everything returns
0/falsewith no error: the inventory resource (vorp_inventory,rsg-inventory, orrsg-inventory_v2) probably isn't running — checkGetResourceStatefor it. - If
AddItemfails withcannot_carry: the player's inventory is full or over weight — this is expected behaviour, not a bug. - If error codes come back as
framework_not_supported: wc_libs started before a framework was detected — check console for the framework-detection warning on resource start.