Loot Tables

From RPG Creation Kit
Jump to navigation Jump to search

In this tutorial we are going to take a look at the new Loot Tables, which allow you to fill your Looting Points (chests, corpses, containers) with randomly generated items instead of placing every item by hand. You can also make the loot scale with the level of the Player.

How Loot Tables Work

A Loot Table is an asset that describes what a container may contain. When the Player opens a Looting Point for the first time, the table is rolled and the result is placed inside its Inventory. The roll happens only once: the result is written on the Save File, so if the Player closes and reopens the container he will always find the same items.

There are two types of assets:

  • Loot Table: a list of guaranteed items plus a pool of random picks based on weights.
  • Leveled Loot Table: a set of Loot Tables divided in level brackets (for example levels 1-10 use one table, 11-20 another one). When it is rolled, it will use the table of the bracket that matches the current level of the Player.

A Loot Table can also contain other Loot Tables: an entry of the pool can point to another table instead of an item. This is very useful to create for example a generic "Random Potion" table and reuse it in many different chest tables.

Creating a Loot Table

Right click in the Project Window and select Create > RPG Creation Kit > Loot > New Loot Table.

The inspector has two sections:

Loottable 1.png

Always Granted

The items you put in the "Guaranteed Items" list are added every time the table is rolled. For each entry you can set:

  • Item: the item to grant.
  • Min Amount / Max Amount: the amount is picked randomly between these two values. If you set Min Amount to 0, sometimes the entry will grant nothing.

Weighted Rolls

This is the random part of the table:

  • Rolls Min / Rolls Max: how many times the pool is rolled. Each roll picks one entry from the pool.
  • Pool: the list of the possible picks. For each entry you can set:
    • Item: the item granted if this entry is picked. Set this OR Nested Table, not both.
    • Nested Table: another Loot Table to roll instead of granting an item. If you set this, the nested table is rolled with its own settings, and the Min/Max Amount of this entry are ignored.
    • Weight: how likely this entry is compared to the others. Weights are relative, they are not percentages: if you have two entries with weight 3 and weight 1, the first one is picked 75% of the times. An entry with weight 0 is never picked.
    • Min Amount / Max Amount: the amount granted when this entry is picked.

Be aware about circular dependency (table A contains table B which contains table A), the Editor will warn you in the Console and the roll will stop at 8 levels of depth instead of freezing the game.

Testing a Table

You don't need to enter Play Mode to test your table: right click on the Loot Table component in the inspector and select "Test Roll". The rolled items and amounts will be printed in the Console. Roll it a few times to get an idea of what the table produces.

Loottable 2.png


Loottable 3.png

Creating a Leveled Loot Table

Right click in the Project Window and select Create > RPG Creation Kit > Loot > New Leveled Loot Table.

Loottable 4.png

A Leveled Loot Table is just a list of "Brackets", for each one you can set:

  • Min Level / Max Level: the range of Player levels of this bracket.
  • Table: the Loot Table used for that range.

When the container is opened, the bracket that contains the current level of the Player is used. If the level of the Player is outside every bracket, the nearest one is used (so a level 50 Player will still get the loot of your 21-30 bracket if that is the highest one you made). If two brackets overlap, the first one wins and the Editor will warn you in the Console.

To test it, set the "Test Roll Level" field in the inspector, then right click on the component and select "Test Roll At Test Level": the Console will show you which table that level resolves to, followed by a test roll of it.

Using a Loot Table on a Looting Point

A Loot Table does nothing by itself, you have to attach it to a Looting Point with the "LootFromTable" component.

1) Select a GameObject that already has a "Looting Point" component (see Creating a New Looting Point if you don't have one).

2) Add a "LootFromTable" component to it.

3) Reference your Loot Table or Leveled Loot Table in the Loot Table field.

Loottable 5.png

The component has two options:

  • Additive: if true, the rolled items are added on top of the items you placed by hand in the Inventory of the Looting Point. If false, the Inventory is cleared before the roll, so the container will only have what the table generates.
  • Apply Ownership: if true, the rolled items get the ownership metadata of the Looting Point, so taking them from an owned container counts as stealing, exactly like the items placed by hand (see Items Ownership, Metadata and Stealing).

The roll happens right before the looting panel opens the first time the Player interacts with the container, using the level of the Player at that moment, and it is then saved on the Save File.

Important: the Looting Point must have Has To Load And Save enabled. If it is disabled nothing is written on the Save File and the loot will re-roll every time the Player opens the container, the Editor will warn you about this in the Console.

Result

Opening the chest in game will now show randomly generated items appropriate to the level of the Player, and the chest will keep its rolled content across saves. Combined with nested tables you can build the entire loot economy of your game from a few reusable assets: one "Gems" table, one "Potions" table, one "Low Level Weapons" table, and every dungeon chest just references them with different weights.

In the Demo's starting cave you will find a crate on a corner as an example on how everything is setup.

Loottable 6.png