Booster Pack?

Hey guys and gals, I am currently trying to work out a booster pack system but I'm stuck.

I have it set up to give the player all the cards as of now, But I want this to be randomized and set it up as a shop so once you pay the event runs and gives you random items.

Here is the code I have so far


for (var i = 0; i < $dataItems.length; i++) {

if ($dataItems && $dataItems.name !== '') {

$gameParty.gainItem($dataItems, 5);

}

}

But not sure how to randomize it. Any ideas?
Math.randomInt(x)+1

This will generate a random number between 1 and x.
Math.randomInt(x)+1

This will generate a random number between 1 and x.

Do I set a value to x? Sorry, I'm new to learning this programming stuff.

Like This?


for (var i = 0; i < $dataItems.length; i++) {

if ($dataItems && $dataItems.name !== '') {

$gameParty.gainItem($dataItems, Math.randomInt(1)+1);

}

}
Yes, you assign an integer value to x. So in your example you would be generating a random number between 1 and 1, so always 1. If you wanted to get a random number between 1 and 10 it would be Math.randomInt(10)+1.

I'll note I don't really have any idea about programming myself so I can't really follow your for loop to say if it will work correctly, but I've got a feeling your $dataItems should be $dataItems[id] (where id = id of item in database)
Yes, you assign an integer value to x. So in your example you would be generating a random number between 1 and 1, so always 1. If you wanted to get a random number between 1 and 10 it would be Math.randomInt(10)+1.

I'll note I don't really have any idea about programming myself so I can't really follow your for loop to say if it will work correctly, but I've got a feeling your $dataItems should be $dataItems[id] (where id = id of item in database)

Thank you. And you're correct, but without it, it allows to obtain all items.

Original thread: https://forums.rpgmakerweb.com/threads/booster-pack.103975/