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 a Loot Box
  • Working with a Loot Box
  • Setting Possible Drops
  • Getting Drop Chances
  • Getting Loot
  1. Scripting API
  2. Items

Loot Box

Scripting with the LootBox class.

A class which can be used to receive a randomized selection of items.

Fields & Properties

Name
Description
Type
Access

id

An ID that can be used to determine if a loot box has already been obtained.

string

public

possibleDrops

A list of all possible item drops.

List<LootBoxDrop>

public

minItemDrop

The minimum amount of items that can be dropped from this loot box.

int

public

maxItemDrop

The max amount of items that can be dropped from this loot box.

int

public

Creating a Loot Box

Since loot boxes are scriptable objects, you can create them with ScriptableObject.CreateInstance.

LootBox lootBox = ScriptableObject.CreateInstance<LootBox>();

Working with a Loot Box

Setting Possible Drops

Creating a Drop List

The code below is an example of how you can create a drop list. In the example, 2 possible drops are added to a loot box, each with a 50% probability of dropping. The myItem and myOtherItem fields are instances of an Item.

lootBox.possibleDrops = new List<LootBoxDrop>()
{
    new LootBoxDrop()
    {
        item = myItem,
        amountRange = new Vector2(0, 64),
        dropRate = 1
    },

    new LootBoxDrop()
    {
        item = myOtherItem,
        amountRange = new Vector2(0, 64),
        dropRate = 1
    },
};

Randomized Drop Amount

A random number of items are dropped based on the minItemDrop and maxItemDrop fields.

// Random range between 1 - 5 items
lootBox.minItemDrop = 1;
lootBox.maxItemDrop = 5;

Getting Drop Chances

You can get the drop chance of each possible drop as a percentage out of 100 by it's index with the CalculateDropChance method.

// Get drop chance of an item drop at index 0
float dropChance = lootBox.CalculateDropChance(0);

Getting Loot

The GetLoot method can be used to get random loot. This can be considered as opening the loot box. This returns an ItemStack list.

var itemStacks = lootBox.GetLoot();
PreviousItem SpawnerNextItem Pouch

Last updated 5 months ago

📄