Inventool Documentation
  • Inventool Documentation
  • đŸ•šī¸Quick Start
    • Installation
    • Start Creating
  • 💡General
    • Running the Demo
    • Menu Options
    • UI Updates
    • UI Customizations
      • uGUI
      • UI Toolkit
    • Custom Item Drops
  • 🎓Tutorials
    • Demo Walkthrough
  • âœī¸Editors
    • Inventool
      • Inventory
      • Equipment
      • Items
      • Currencies
      • Crafting
      • Dismantling
      • Enchanting
      • Stats
        • Stat IDs
        • Attributes
      • Settings
    • Item Type Manager
    • Localization Editor
    • Stats Editor
    • Merchants
      • Shopkeeper
      • Craftsman
      • Enchanter
    • Storage
    • Loot
      • Loot Box
      • Item Pouch
      • Currency Pouch
    • Components
      • Initializer
      • UI
        • uGUI
          • Inventool Window
          • Split UI
            • Inventory Window UGUI
            • Equipment Window UGUI
            • Key Items Window UGUI
            • Crafting Window UGUI
            • Enchanting Window UGUI
            • Storage Window UGUI
            • Shop Window UGUI
            • Selector UGUI
          • Action Menu UGUI
          • Hover Details UGUI
          • Confirm Prompt UGUI
          • Quantity Prompt UGUI
          • Character Viewer Element UGUI
        • UI Toolkit
          • Inventool Window
          • Split UI
            • Inventory Window
            • Equipment Window
            • Key Items Window
            • Crafting Window
            • Enchanting Window
            • Storage Window
            • Shop Window
          • Action Menu
          • Hover Details
          • Confirm Prompt
          • Quantity Prompt
        • Character Viewer
      • Overworld Merchant
      • Storage Keeper
      • Item Drop
      • Item Spawner
      • Input
        • Cross Input Support
        • Cross Input Support UGUI
          • Target Selectable
  • 📄Scripting API
    • Initialization
    • Inventory
    • Equipment
      • Equipment Slot
    • Items
      • Item
      • Item Type
      • Item Stack
      • Item Drop
      • Item Spawner
      • Loot Box
      • Item Pouch
    • Currencies
      • Currency Identity
      • Currency
        • Value
      • Currency Pouch
    • Crafting
      • Craft
      • Crafter
    • Enchanting
      • Enchantment
    • Stats
      • Stat Identity
      • Attribute
      • Stat
        • Stat Value
          • Value
        • Effectiveness
      • Stat Profile
    • Storing
      • Storage
      • Storage Keeper
    • Settings
    • Merchants
      • Shopkeeper
      • Craftsman
      • Enchanter
      • Overworld Merchant
    • UI
      • uGUI
        • Inventool Window UGUI
        • Split UI
          • Draggable Window UGUI
            • Inventory Window UGUI
            • Equipment Window UGUI
            • Key Items Window UGUI
            • Crafting Window UGUI
            • Enchanting Window UGUI
            • Storage Window UGUI
            • Shop Window UGUI
          • Selector UGUI
        • Action Menu UGUI
        • Hover Details UGUI
        • Confirm Prompt UGUI
        • Quantity Prompt UGUI
        • Draggable Element UGUI
          • Equipment Slot Element UGUI
          • Item Slot Element UGUI
          • Item Stack Element UGUI
        • Action Menu Option UGUI
        • Currency Element UGUI
        • Inventory Filter UGUI
        • Inventory Slot UGUI
        • Key Item Element UGUI
        • Shop Item Element UGUI
        • Storage Currency Element UGUI
        • Stat Element UGUI
      • UI Toolkit
        • Inventool Window
        • Split UI
          • Draggable Window
            • Inventory Window
            • Equipment Window
            • Key Items Window
            • Crafting Window
            • Enchanting Window
            • Storage Window
            • Shop Window
        • Action Menu
        • Hover Details
        • Confirm Prompt
        • Quantity Prompt
        • Item Elements
          • Item Stack Element
          • Equipment Slot Element
          • Item Slot Element
          • Shop Item Element
      • Action Menu Option
      • Character Viewer
    • Events
    • Sounds
    • Saving & Loading
      • Inventory & Equipment
      • Storage
    • Input
      • Cross Input Support
      • Cross Input Support UGUI
    • Localization
      • Localization Settings
      • Localizer
  • đŸ› ī¸Support
    • Getting Help
  • 📚Changelogs
    • Latest Releases
    • Future Plans
  • ⭐Rate Me?
Powered by GitBook
On this page
  • Fields & Properties
  • Creating Shopkeepers
  • Filters
  • Get Filters
  • Set Filter
  • Remove Filter
  • Get Items
  • Buying Items
  • Selling Items
  1. Scripting API
  2. Merchants

Shopkeeper

Scripting with the Shopkeeper class.

A Shopkeeper is a merchant that buys and sells items.

Fields & Properties

Name
Description
Type
Access

items

A list of items that this shopkeeper sells.

List<Item>

public

activeItemTypeFilter

The active item type filter.

ItemType

public

Creating Shopkeepers

It's not recommended to create shopkeepers at runtime, but it is possible. Shopkeeper's are scriptable objects which cannot be created as assets at runtime for later use.

Shopekeeper myShopkeeper = ScriptableObject.CreateInstance<Shopkeeper>();

Filters

Get Filters

You can get all ItemType filters of a shopkeeper with the GetFilterTypes methods.

var myfilters = myShopkeeper.GetFilterTypes();

Set Filter

By setting the filter, only the items that match the filter will be returned by the GetItems method. You will need a reference to an Item Type to set the filter.

myShopekeeper.SetItemFilter(myItemType);

Remove Filter

myShopkeeper.RemoveItemFilter();

Get Items

You can get items wit the GetItems method. If no filter is active, all items will be returned. Otherwise, only the items that match the filter will be returned.

var items = myShopkeeper.GetItems();

Buying Items

You can but an item from a shopkeeper with the TryBuyItem method. This method returns true if the item was bought successfully. You will need a reference to an Item. Buying may fail if the player does not have sufficient funds, lacking space in their inventory, or the shopkeeper does not sell the item. If successful, the item will appear in the player's inventory, and the cost will be subtracted from their funds.

quantity is an int that sets the amount of the item to purchase.

bool result = myShopkeeper.TryBuyItem(myItem, quantity);

Before committing to this method, you have the option of checking if the item can be bought with CanBuyItem method.

bool result = myShopkeeper.CanBuyItem(myItem, quantity);

Selling Items

You can sell an ItemStack to a shopkeeper with the TrySellItem method. This method returns true if the item was sold successfully. You will need a reference to an ItemStack. Selling may fail if the player does not own the item or the item is not sellable. If successful, the item will be removed from the player's inventory and the selling cost will be added to the player's funds.

quantity is an int that sets the amount of the item to sell.

bool result = myShopkeeper.TrySellItem(myItemStack, quantity);

Before committing to this method, you have the option of checking if the item can be sold with CanSellItem method.

bool result = myShopkeeper.CanSellItem(myItemStack);
PreviousMerchantsNextCraftsman

Last updated 5 months ago

📄