Luck based item gathering?

Henlo again!

I'm trying to make gather spots in my map that utilize the Luck parameter to have a chance at getting better items within a certain amount of possible item slots.

Let's say I want to pick up berries from a bush.
Out of 5 possible slots I can get berries or branches.

So let's say I gather it once and I get:
  • 4 branch / 1 berries
Then with higher luck I would get:
  • 2 branch / 3 berries
Then with even higher luck:
  • 1 branch / 4 berries
I would like this randomized and not necessarily set in stone, luck would only favor berries more than branches but you could possibly still get mostly branches even with high luck sometimes.

Currently I have a variable for the random quantities between 1 and 5 that controls 2 other variables called gather_point_good and gather_point_bad which give either a bad item (branches) or good one (berries).
Spoiler: Images
jA2GEQo.png

uK27gBW.png

hKLOEXH.png

eBnOwlZ.png

The problem is that with this setup, together they aren't limited by 5, for example I can get 4 berries and 4 branches in the same action, clearly going over the limit of 5 I wanted to set.
On top of that I have no idea how to make it so luck would favor one item more than the other.

I think my eventing knowledge is a bit too bare-bones for this concept 🙁

Hope someone could give me a hand and thanks for reading!
Here is how you'd do it - the exact numbers will depend on your preferences and your stats.

First you make a random number based on your LUK. Event command, third tab, Script:
Code:
$gameVariables.setValue(X, Math.random()*$gameParty.leader().param(7));
where X is the ID of a variable you've set aside for this purpose.

Then you just go down the list...
If that variable > 80, give a berry, else give a branch
If that variable > 60, give a berry, else give a branch
If that variable > 40, give a berry, else give a branch
If that variable > 20, give a berry, else give a branch
Give a branch

And you tweak that math however you like. The numbers I put in make the most sense if your LUK goes from 1-100, you adjust the probability however it makes sense for you. And I left the last line so they're always getting one branch, but you could replace it with another check if you wanted.
Thank you that really helped! You just saved my butt with that script!

Original thread: https://forums.rpgmakerweb.com/threads/luck-based-item-gathering.140484/