Help on setting up weighted loot table

Hi!
I am making small fishing game and for that I need weighted loot table which determines different chances to catch different fish. For that I made Array with fish names and weights (chances to catch that fish).

Expected outcome is to get fish name according to it’s weight after rolling random number. Looks like only first part is working (calculating total weight and random number).

These are some debugging numbers:

And my current event sheet:

I suspect that problem is somewhere in the “For every child loop” but I can’t figure it out. Any help on this topic would be much appreciated.
All this test is based on only video I found about Weighted Loot Tables. It is for UE4 but guy in the video explains the logic behind loot tables very well. II just can’t recreate that in Gdevelop.

Link to that video if it helps:

Thanks in advance.

I think the simplest method to implement in GDevelop is to:

  1. Create a new array, say called fish_randomiser.
  2. In a beginning of the scene event, loop through each entry in Fish_DB, and insert the fish name it’s weight number of times. So you’ll end up with 5 Trout, 10 Carp, 4 Eels etc, in the array.
  3. Then you just generate a random number using Random(VariableChildCount(fish_randomiser)). This will give you a random fish based on their weighting.
1 Like

Thanks! So far this solution works, I get random number based on new weight sum from new array. Next thing I can’t figure out is what expression to use to get actual fish name.

fish_randomiser[Random(VariableChildCount(fish_randomiser)-1)] 

When you use a random number with the array child count , you need to subtract 1 because the array and random() both start at zero.

If the size was 5 then the elements or indexes would be from 0 to 4. So, random(4) or count minus 1.

Does it? I don’t understand how you can say that given the numbers in your screen shot.

What fish name are you expecting from the random value 0.9? All of them fit the bill - a Random_Number of 0.9 is less than all of the fish weights, so all of them are valid fish options and the weightings doesn’t play a role in the selection.

You are trying to achieve something that’s suitable for Unreal 4, but doesn’t translate easily into GDevelop. I’ve given you a method that is very suitable for GDevelop (you could event shuffle the Fish_DB) and will work (with @Keith_1357’s correction of my noob oversight). It’s simple and efficient. If it were up to me, I’d stop trying to implement something rather complex and go with the easier method that’s fits GDevelop’s logic flow.


BTW, Random_Number in these 4 lines isn’t needed - you can just replace it in the first two actions with Current_Number, and delete the last 2 actions:

image

Sorry, I could word my answer better. I meant that your solutions is working fine, screenshot was from my first attempt which failed. Thank you very much for your help.

Thank you. Yes, my example in screenshots wasn’t working but now it works when I changed code as MrMen suggested. I also fixed issue with random number which is now from 0 to total count -1.

1 Like