InventoryBroadcasts - jimdroberts/FishMMO GitHub Wiki

Description

Defines broadcast structures for character inventory actions, including setting, removing, and swapping items. Used for networked communication of inventory changes between client and server.


API Access

Fields

  • public struct InventorySetItemBroadcast : IBroadcast

    Broadcast for setting a single item in the character's inventory. Contains all data needed to place or update an item in an inventory slot.

    • long InstanceID: Unique instance ID of the item.
    • int TemplateID: Template ID of the item type.
    • int Slot: Slot index in the inventory.
    • int Seed: Seed value for item randomization or uniqueness.
    • uint StackSize: Stack size of the item.
  • public struct InventorySetMultipleItemsBroadcast : IBroadcast

    Broadcast for setting multiple items in the character's inventory at once. Used for bulk updates or synchronization.

    • List Items: List of items to set in the inventory.
  • public struct InventoryRemoveItemBroadcast : IBroadcast

    Broadcast for removing an item from a specific inventory slot.

    • int Slot: Slot index to remove the item from.
  • public struct InventorySwapItemSlotsBroadcast : IBroadcast

    Broadcast for swapping two item slots in the inventory or between inventories.

    • int From: Source slot index.
    • int To: Destination slot index.
    • InventoryType FromInventory: Type of inventory the item is being moved from.

Basic Usage

Setup

  1. Use these broadcast structs to send and receive inventory actions between client and server.
  2. Populate the fields as required for each inventory operation (set, remove, swap, etc.).

Example

// Example 1: Setting a single item in the inventory
InventorySetItemBroadcast setItem = new InventorySetItemBroadcast {
    InstanceID = 12345,
    TemplateID = 1001,
    Slot = 5,
    Seed = 42,
    StackSize = 10
};
networkManager.ClientManager.Broadcast(setItem);

// Example 2: Swapping two item slots
InventorySwapItemSlotsBroadcast swap = new InventorySwapItemSlotsBroadcast {
    From = 2,
    To = 7,
    FromInventory = InventoryType.Inventory
};
networkManager.ClientManager.Broadcast(swap);

Best Practices

  • Always validate slot indices and item data before sending or processing broadcasts.
  • Use bulk updates for efficient synchronization of large inventories.
  • Keep inventory logic modular and well-documented for maintainability.
  • Use the provided broadcast structs for clear, type-safe network communication.
⚠️ **GitHub.com Fallback** ⚠️