← Back to all addons

Create Runtime Loot Tables - Chests

Posted by MrMystery on Jul 15, 2025 at 12:34 AM

GameplayFeature3.0 Verified
šŸ’” 2

This is an update to the way Chest.cs works, and utilizes a random Scriptable Object LootTable. Minimal changes to basic Mythril, so it’s pretty much drop in, and will not break anything else that you’re in the middle of, or have already done with Chests in the game. What is does, is when a player opens a chest, it checks what level they currently are, and rolls loot based on the Loot Table you setup, with level ranges on the loot, so you can have more open world, as the monsters scale with player, so does the chest loot. Works well in procedural dungeons as well:

Here’s the steps to get this working, firstly, you need this script: LootTable.cs

This is the new randomizer - you can see in the screen shot what a demo one looks like.

The next part is super important, in Chest.cs, please make these two changes:

Add

[SerializeField] private LootTable m_lootTable;

I added it right under ChestLoot m_loot;

Secondly in TryOpen(), right inside if (!m_opened)

public async Task<bool> TryOpen()
{
    if (!m_opened)
    {
        if (m_loot.IsEmpty() && m_lootTable != null)
        {
            m_loot = m_lootTable.RollLoot(GameManager.Player.level);
        }
        else if (m_lootTable != null)
        {
            var extraLoot = m_lootTable.RollLoot(GameManager.Player.level);
            List<ChestLootEntry> combinedEntries = new List<ChestLootEntry>();

            if (m_loot.entries != null)
                combinedEntries.AddRange(m_loot.entries);
            if (extraLoot.entries != null)
                combinedEntries.AddRange(extraLoot.entries);

            m_loot.entries = combinedEntries.ToArray();
            m_loot.money += extraLoot.money;
        }

//LEAVE EVERYTHING ELSE JUST ADD THE STUFF ABOVE - should come right before these two lines:
        TryPlayOpeningAnimation(true);
        TryPlayContentRevealAnimation();

So what this does:

  1. Normal Chest Loot Table intact - so put quest items, or guaranteed loot - or leave empty - doesn’t matter…
  2. Make a Loot Table SO - like the screen shot, with level ranged loot, and assign the loot table to the chest - or don’t - works either way
  3. What the player gets - ALL the loot you assigned - the static loot from the chest and the random loot from the table if one is assigned

How the Loot Table Works:

  1. Loot Groups:
    • Groups of items you want, and the change for rolling those items, for instance, in my screenshot you see consumables… chance = 1.00 (100%) number of rolls = 2 min / max level

So you will have a 100% chance to get 2 items from the loot table in this group, if you are level 1-5

In the second group called Items - .5 (50% chance) - 2 rolls - level 1-20… so you get 2 chances at 50% - i.e., you could get 0, 1 or 2 items from this groups loot pool.

  1. Drops: If the player passes a roll % chance to get an item, it will check the combined weights of the loot, and then select and item - and assign a quantity based on the min/max

So in the items one, we have Iron Sword 10, Iron Plate 10, Lucky Sword, 1…. so each time you open the chest, you have 1: 50% chance, to get 10/21 Iron Sword, 10/21 Iron Plate, or 1/21 Lucky Sword 2: Second 50% chance to get the same…

Hope this is clear - and useful in your projects!

šŸ“œ Scripts

šŸ’¬ Comments (5)

Gyvr Jul 15, 2025 at 12:44 AM
Soooo awesome eyesshaking
Gyvr Jul 15, 2025 at 12:47 AM
I think this feature has been requested before, so I’m sure a few folks will be REALLY happy with this one
MrMystery Jul 15, 2025 at 02:34 PM
minor update to the loot table - realized I neglected gold so - put gold on an animation curve based on level, so you can scale gold value, simple math of multiplying gold by (1 + animationCurve) - so at level 1 if you leave it at 0F on the curve, you get the base gold, and at level 5 the curve can be at like… .5F (so you get gold * 1.5) or 50% more gold… or make it like 9F … so you end up with 10x more gold, whatever fits your game

šŸ“œ Scripts

partyparrot 1
MrMystery Jul 15, 2025 at 02:37 PM
Create Runtime Loot Tables - Chests
MrMystery Jul 15, 2025 at 02:58 PM
Also if you’re looking to add this same Loot Table to your monsters, based on the monsters level when it dies - check out this <#1394694396301021347> it use the same Scriptable Object to make life uniform and simple šŸ˜‰
eyesshaking 1

Want to continue the conversation?