Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How do you handle loot tables and drop chances?  (Read 4783 times)
0 Members and 1 Guest are viewing this topic.
Offline tyeeeee1
« Posted 2013-08-09 01:56:04 »


The question is in the title; How do you handle loot tables and drop chances?

The way I'm currently handling them can be seen in the link below within the getNextDrop method. It seems like a pretty bad way to do loot tables/drop chances but it works for the moment.
Offline wessles
« Reply #1 - Posted 2013-08-09 02:39:43 »

I dont get what you are asking. I usually just make there a 0.1/100 chance. Not much else to it. Do you mean making an organized table of chances? In that case, just have an int array (not float array! less memory used, so just use multiplication knowledge), and reference them with constants corresponding to each drop.

public static final int APPLE=0, IRON=1, GOLD=2, DIAMOND=3
public static final int[] chances = new int[10, 6, 4, 1]

public static float getDropChance(int type) {
    return chances[type]*.01f;
Offline tyeeeee1
« Reply #2 - Posted 2013-08-09 03:02:49 »

What I mean is how do you, whoever is reading, go about creating a bunch of drop tables, fill them with items and drop chances and then figure out which items to draw in your games.

The way I do it is above in the github link but I basically fill an int array with the itemIDs and a double array with the drop chances. Then send those into a method to set everything up. Then to figure out what items to drop I create a random float between 0.0 and 1.0 then multiply the float by 100 and any items with drop chances higher than the float will be dropped.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wessles
« Reply #3 - Posted 2013-08-09 03:05:04 »

That really depends on your object framework. There are so many, Ill just let you find them yourself. I don't mean the broad term kinds, but the high level frameworks that differ with each programmer, unless you are copying someone else. Really, there are a ton of ways. Just experiment!
Offline drabla

Junior Devvie

Medals: 5

« Reply #4 - Posted 2013-08-09 04:19:10 »

Here is how we did it some years ago - This was for a game with lots of items

We had a Webinterface on which we could add items to a Boss / Mob. The Lootable could be exported and looked kind of like this:


Every time a boss was loaded (start of level) , a random number between 1 and 100 was drawn for each item on the list.
DropChance was multiplied by the random number. If it was >= 1 we added it to a Collection.

Every Boss/Mobb had a chance to drop say 3 -6 items.
We would than randomly pick (random.nextInt(3) + 3) items from that Collection and wait for the boss to go down.

In the loottable were always enough dropChance = 1.0  items to guarantee something would drop.

Crazy times... Smiley
Offline Cero
« Reply #5 - Posted 2013-08-13 12:46:30 »

Yeah basically like that

every enemy has a droplist: a list of items and the chance in percent.
In my case thise has to be a per enemy list because in my game enemy A could drop a potion with 10% while enemy b could drop it at 30%
if in our game you would say: well no matter who drops it, they always have fixed chances, then you could simplify.
then I would do this per text file - you CAN use xml or json, and you would like to write a small tool for it...

Offline RobinB

JGO Ninja

Medals: 45
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #6 - Posted 2013-08-13 13:35:30 »

i guess you should loop trough all droppable items.
Each item gets checked against its own random value.
This way not all items with > 30% drop when the number is 30;

Like this:
Chance / CurrentRandom / Item
.01    .0324    1
.10    .1243    2
.22    .3679    3

So this pass only item 1 drops, while the other items had a bigger chance.
Pages: [1]
  ignore  |  Print  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (74 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!