Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loot tables

Started by DarkZoulz Jan 16, 2008 at 9:38 AM 3 replies 6.3k views
Original Post
DarkZoulz
DarkZoulz
I'm sure this has been discussed before, but I'm working on a looting system for my game (which is a hack 'n slash type deal). I figure i'd go with the classic loot table system. Each enemy has a table of items that they can drop, and each item has a certain percentage of getting dropped. This seems like quite a good system to me, except for the fact that items at the top of the list are more likely to drop than those at the bottom. Let's say I roll successfully for item #2 in the loot table and generate that item for the player. What if item #5 also would have been a successful roll? How would I go about giving all the items in the loot table a "fair" chance of being selected? Are there any other smart ways of distributing loot?
stonemetal
stonemetal
Rather than go down the list and trying each item individually, assign a range to each item. Since you want to use percentages make the roll from 1 to 100 then assign loot #1 1 to 5, #2 6 to 15 and so on. This will cause you to only ever drop one item at most.

If you want the chance to drop multiple items, do what you are doing now just don't stop after item #2 dropped keep going and see if other items drop. Or you could do the above then assign a range for dropping this and that. One thing to remember if you do that though is the percent chance of dropping #1 is equal to percent chance of #1 by itself + percent chance of the sum of all groups #1 is apart of.
Tjaalie
Tjaalie
Loop trough the list and test each item for a propable drop, if droped add to a new list. At the end of the iteration randomly pick one.
if (*pYou == ASSHOLE) { pYou->Die(); delete pYou; };
DarkZoulz
DarkZoulz
Quote:
Original post by Tjaalie
Loop trough the list and test each item for a propable drop, if droped add to a new list. At the end of the iteration randomly pick one.


That was actually a really good idea. And simple at that. Thanks to both of you!
Symphonic
Symphonic
It's hard to see without an example how item 5 could have been an option for a roll of item 2.

That said, a good approach is thus:

Give each item in the loot table just a raw score (not a probability!)

Nothing 1000
Useless Dagger 100
Magical Fluff 10
Useful Belt 1

Loosely speaking, the idea is that Nothing is ten times as common as a useless dagger, which is ten times as common as magical fluff, which is... you get the idea.

Now we normalize the scores to give probabilities:

sum = (S1 + S2 + S3 + S4)
P1 = S1 / sum
P2 = S2 / sum
P3 = S3 / sum
P4 = S4 / sum

so the loot table looks something like this now:

P1 - Nothing
P2 - Useless Dagger
P3 - Magical Fluff
P4 - Useful Belt

such that the sum of the Pn's is equal to one. Then your creep dies, and you generate a random number R, and do something like this (python pseudocode):

r = Random()choice = -1for i in range(0,size_of_loot_table):    if r > P:        r -= P    else:        choice = i


In this way, the random number is depleted until it is less than one of the probabilities. This system is order independent (you can put the rare stuff earlier if you want) as well.
Geordi
George D. Filiotis

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.