How does loot table in games work

886 views

How does programmers do loot tables for millions of items that all have different chances to drop when you kill a enemy in big games like path of exile , Diablo, WoW.

In: Mathematics

3 Answers

Anonymous 0 Comments

Well, I’m not 100% sure, but I assume it works by having the game generate a random number, and for different ranges of of what the number is, a different item is obtained.

For a simple example, let’s assume there’s a loot table with 5 items, one really common, two equally uncommon, one rare, and one very rare.

The game would generate a random number between 1 and 100.

If the number is from 1 to 40, you’d get the very common item.

If the number is from 41 to 65, you’d get the first uncommon one.

If it’s between 66 and 90, you’d get the second uncommon item.

If it’s between 90 and 99, you’d get the rare one.
If it’s exactly 100, you’d get the very rare drop.

Instead of having just 5 items and the random number generated between 1 and 100, you’d have a higher number of items in the drop table, and the random number generated be between 1 and 10 million or something, with each item’s drop range being much wider than 1 number or even 40 numbers.

Anonymous 0 Comments

Firstly it’s not millions of items, it’s maybe a few thousand base items with a bunch of potential random attributes (for games that use a random attribute system).

Secondly there’s different ways of doing it, but a basic system might be:

* A database/table of all base items (and whatever rules are associated with those items for random attributes, and the odds of those attributes occurring on the item).
* A bunch of loot tables that have certain items from the item database linked to them, with whatever random chance each item has of dropping.
* NPCs, chests (anything that drops loot) with one or more loot tables linked to it.

When you loot the NPC, chest, etc, the game does some random number generation. It then compares that number(s) to the linked loot table(s) to determine what drops. If the items have random attributes, the game also generates some more random numbers to determine what attributes the item ‘rolls’ with, and how good those attributes are.

The generated item becomes a unique entry in a database/table somewhere (but not in the base item database), most usually stored with the character (or shared bank, or whatever) where the item resides. So in essence the “milllions of items” that you’re thinking of exist as unique entries on unique “loot tables” of thousands of characters.

This isn’t the only way to do it, though. The game might very well just have one massive database to store all unique items.

A handy place where you can actually see this in action is the construction kit for The Elder Scrolls series and Fallout series.

Anonymous 0 Comments

1) Assign weight and order to each item.

> 5 Sword
> 10 Shield
> 4 Potion
> 1 Wand

2) Sum together their weights (X=20)

3) Prepare table by summig giving each item index that is sum of all previous weights

> 0 Sword
> 5 Shield
> 15 Potion
> 19 Wand

You will have all this prepared beforehead in data structure.

3) Roll X sided dice and find first item in table that has lower index than that.

If you roll 1, 2, 3, 4, 5 you get sword.

If you roll 16, 17, 18, 19 you get potion and 20 gets you wand.

You can very easily find right index by bisecting the table with log(N) performance.

You can very easily fine tune chance by using bigger numbers.

> 4154 Nothing
> 15556 Trash item
> 550 Sword
> 984 Shield
> 156 Potion
> 1 Wand

Gives you

> 19.4% Nothing
> 72.6% Trash item
> 2.5% Sword
> 4.5% Shield
> 0.7% Potion
> 0.004% Wand

Table would look like:

> 0 Nothing
> 4154 Trash item
> 19710 Sword
> 20260 Shield
> 21224 Potion
> 21400 Wand

You roll ‭21401 sided dice‬