🤠 Wild Country Libs
Server API

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.

Server only. Do not call these exports from client code. Inventory changes must stay server-authoritative so clients cannot spoof rewards, purchases, or delivery turn-ins.
GetItemCount(source, item, metadata?)server

Returns how many of an item the player has. Invalid inputs, missing inventory resources, or unsupported frameworks return 0.

ParamTypeDescription
sourceintegerPlayer server ID.
itemstringInventory item name.
metadatatable | nilOptional metadata filter where supported.
example
local count = wc:GetItemCount(source, 'corn')
CanCarryItem(source, item, amount, metadata?)server

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.

AddItem(source, item, amount, metadata?)server

Adds an item after validation and a carry check.

ReturnsDescription
boolean, string | niltrue on success, otherwise false, errorCode.
example - reward
local ok, err = wc:AddItem(source, 'delivery_token', 1)
if not ok then
  print('Could not add item:', err)
end
RemoveItem(source, item, amount, metadata?)server

Removes items only when the player has enough. SubItem is an alias.

example - sale
local ok, err = wc:RemoveItem(source, itemName, quantity)
if not ok then return false, err end
HasItem(source, item, amount?, metadata?)server

Boolean helper for GetItemCount(source, item, metadata) >= amount. Amount defaults to 1.

Supported Frameworks

FrameworkInventory pathNotes
VORPvorp_inventoryUses getItemCount, canCarryItem, addItem, and subItem/removeItem.
RSGrsg-core player functionsUses 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

before - local framework wrapper
if invGetItemCount(source, itemName) < qty then return end
invSubItem(source, itemName, qty)
after - wc_libs
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.

wc_corndelivery/server/main.lua
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

Security notes

Security. Item names, amounts, and metadata should never come straight from client input for anything that pays out money or grants a reward. Treat the client event as "please check if I qualify," and let the server look up what the player actually has and what it's actually worth.

Troubleshooting