Class

RezInventory

RezInventory()

Constructor

# new RezInventory()

Manages a collection of slots that can hold items.

An inventory is a container system that organizes items into typed slots. Each slot can accept items of a specific type and may have capacity limits. Inventories can be owned by actors, enabling equipment systems with effects.

Key features:

  • Typed Slots: Each slot accepts only items of a matching type
  • Capacity: Slots can have size limits based on item sizes
  • Effects: Items can apply effects to the inventory's owner when inserted
  • Events: Triggers events on insert/remove for items, slots, and inventory

Slots are defined as a binding list on the slots attribute where each binding key (prefix) is the slot position name and the value is a reference to a @slot element that defines the slot's type configuration. Multiple positions can share the same slot type definition.

Define in Rez:


@inventory player_inv {
  slots: [weapon: #s_weapon, armor: #s_armor]
  initial_weapon: [#item_sword]
}

View Source rez_inventory.js, line 5

Example

Add an item at runtime

const inv = $("player_inv");
if(inv.canAddItemForSlot("weapon", "item_axe").result) {
  inv.addItemToSlot("weapon", "item_axe");
}

Extends

Methods

# static addItemToSlot(slotBinding, itemId)

adds the given item to the given slot, notifying inventory, slot & item and applying effects

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 439

# static addSlot(slotBinding, slotId)

add a new slot to the inventory

Parameters:
Name Type Description
slotBinding string

the binding prefix for the slot position

slotId string

the slot element id (unused but kept for API clarity)

View Source rez_inventory.js, line 71

# static appendItemToSlot(slotBinding, itemId)

appends the given item to the given slot

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 225

# static appendToSlot(slotBinding, itemOrItems)

add either a single item_id or an array of item_ids to the slot

Parameters:
Name Type Description
slotBinding string
itemOrItems string | array

either an item_id or array of item_id's to append to the slot

View Source rez_inventory.js, line 236

# static applyEffects(slotBinding, itemId) → {boolean}

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 482

whether the effect was applied

boolean

# static canAddItemForSlot(slotBinding, itemId) → {RezDecision}

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 378

decision object with result

RezDecision

# static canRemoveItemFromSlot(slotBinding, itemId) → {RezDecision}

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 412

decision object with result

RezDecision

# static clearSlot(slotBinding)

remove all items from the given slot, removing any effects granted by those items

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 563

# static containsItem(itemId) → {string|undefined}

Parameters:
Name Type Description
itemId string

View Source rez_inventory.js, line 296

binding prefix of the slot containing the item, or undefined

string | undefined

# static countItemsInSlot(slotBinding) → {integer}

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 275

number of items in the given slot

integer

# static disableSlot(slotBinding)

Disables the slot so no further items can be added to it.

Parameters:
Name Type Description
slotBinding string

the binding prefix identifying the slot position

View Source rez_inventory.js, line 201

Example
$("player_equip").disableSlot("ring2");

# static elementInitializer()

called as part of the init process this creates the initial inventory slots

View Source rez_inventory.js, line 45

# static enableSlot(slotBinding)

Enables the slot so items can be added to it.

Parameters:
Name Type Description
slotBinding string

the binding prefix identifying the slot position

View Source rez_inventory.js, line 188

Example
$("player_equip").enableSlot("ring2");

# static getFirstItemForSlot(slotBinding) → {string}

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 118

id of first item in the slot

string

# static getItemsForSlot(slotBinding) → {array}

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 128

contents of the specified slot

array

# static getSlot(slotBinding) → {object}

Parameters:
Name Type Description
slotBinding string

the binding prefix identifying the slot position

View Source rez_inventory.js, line 103

reference to the slot element for this binding, or throws if the binding does not exist in this inventory.

object

# static getSlotBindings() → {array}

View Source rez_inventory.js, line 86

array of {prefix, slot} objects for every slot position in this inventory

array
Example
for(const {prefix, slot} of inv.getSlotBindings()) {
  const available = inv.isSlotAvailable(prefix);
  // render slot UI using prefix (binding name) and slot (RezSlot object with name, accepts, etc.)
}

# static isBlockedByExclusion(slotBinding) → {boolean}

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 333

true if an occupied slot excludes this slot, or this slot excludes an occupied slot

boolean

# static isSlotAvailable(slotBinding) → {boolean}

Useful for greying out slot categories in inventory UI.

Parameters:
Name Type Description
slotBinding string

the binding prefix identifying the slot position

View Source rez_inventory.js, line 149

true if the slot is not blocked by any exclusion rule

boolean

# static isSlotEnabled(slotBinding) → {boolean}

Slots default to enabled. Use initial_{prefix}_enabled: false in the inventory definition to start a slot disabled, then call enableSlot() at runtime when the player unlocks it (e.g. on reaching a required level).

Parameters:
Name Type Description
slotBinding string

the binding prefix identifying the slot position

View Source rez_inventory.js, line 160

true if the slot has been enabled

boolean
Examples

Define a locked slot in Rez

// @inventory player_equip {
//   slots: [ring1: #s_ring, ring2: #s_ring]
//   initial_ring2_enabled: false
// }

Unlock at runtime

if(player.level >= 5) {
  $("player_equip").enableSlot("ring2");
}

Check in UI

for(const {prefix, slot} of inv.getSlotBindings()) {
  const enabled = inv.isSlotEnabled(prefix);
  const available = inv.isSlotAvailable(prefix);
  // enabled=false → locked; available=false → excluded by another equipped item
}

# static itemFitsInSlot(slotBinding, itemId) → {boolean}

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 309

true if the item will fit with any other contents of the slot

boolean

# static removeEffects(slotBinding, itemId)

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 541

# static removeItemFromSlot(slotBinding, itemId)

removes the specified item from the specified inventory slot

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 507

# static setItemForSlot(slotBinding, itemId)

replaces any existing item content for the slot with this item

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 253

# static setItemsForSlot(slotBinding, items)

replaces any existing item content for the slot with these items

Parameters:
Name Type Description
slotBinding string
items array

array of item ids

View Source rez_inventory.js, line 264

# static setSlot(slotBinding, itemIds)

Parameters:
Name Type Description
slotBinding string
itemIds array

array of item id's

View Source rez_inventory.js, line 214

# static shouldApplyEffects(slotBinding) → {boolean}

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 465

whether effects should be applied for this slot

boolean

# static slotAcceptsItem(slotBinding, itemId) → {boolean}

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 363

true if the given item has a type that this slot accepts

boolean

# static slotContainsItem(slotBinding, itemId) → {boolean}

Parameters:
Name Type Description
slotBinding string
itemId string

View Source rez_inventory.js, line 285

true if the item_id is in the slot

boolean

# static slotIsOccupied(slotBinding) → {boolean}

Parameters:
Name Type Description
slotBinding string

View Source rez_inventory.js, line 139

true if there is at least one item in the slot

boolean