Create Runtime Loot Tables - Monsters
I separated these two out, so they are easier to follow along, and they can be used independently, or use them both. See <#1394477177721979010> for adding this to Chests. To make everyone’s life more simple, this uses the same Scriptable Object as my Random Chest Loot add-on, so if you implemented that you don’t need a second LootTable.cs.
What this script does is - allow you to use the static loot system already included with Mythril - so anything you have previously setup will still work. But adds the ability to attach a Random Loot Table Scriptable Object to a Monster Character Sheet, which allows for scalable loot tables, and gold based on Monster Level.
LootTable.cs is the same as the Chests add-on but it’s attached here again.
Also, you will need to modify two other scripts:
MonsterSheet.cs, after public Loot[] potentialLoot; add:
public LootTable randomLootTable;
This will let you attach the Loot Table Scriptable Object to the Monster Sheet.
Secondly, we need to modify how loot is distributed on a monsters death, so change Monster.cs:
public override void Kill()
{
base.Kill();
if (!m_isSummoned)
{
GameManager.NotificationSystem.monsterKilled.Invoke(m_sheet);
List<ChestLootEntry> lootEntries = new List<ChestLootEntry>();
int totalMoney = 0;
// Static Loot
foreach (Loot entry in m_sheet.potentialLoot)
{
if (GameManager.Player.level >= entry.minimumPlayerLevel &&
m_level >= entry.minimumMonsterLevel &&
entry.IsAvailable() &&
entry.ResolveDrop())
{
lootEntries.Add(new ChestLootEntry
{
item = entry.item,
quantity = entry.quantity
});
}
}
// Static Money
totalMoney += m_sheet.money[m_level];
// Randomized Loot
if (m_sheet.randomLootTable != null)
{
ChestLoot rolledLoot = m_sheet.randomLootTable.RollLoot(m_level);
if (rolledLoot.entries != null)
lootEntries.AddRange(rolledLoot.entries);
totalMoney += rolledLoot.money;
}
// Final Loot
foreach (var entry in lootEntries)
{
GameManager.InventorySystem.AddToBag(entry.item, entry.quantity, EItemTransferType.MonsterDrop);
}
if (totalMoney > 0)
{
GameManager.InventorySystem.AddMoney(totalMoney);
}
GameManager.Player.AddExperience(m_sheet.experience[m_level]);
m_sheet.executeOnDeath?.Execute();
}
}
That’s it, you now have a random loot table on monsters, which will give out loot based on the level of the monster killed - in addition to all the base Mythril Loot settings you may have in place for quests or otherwise:


💬 Comments (1)
Want to continue the conversation?