(Answered) Random chest loot with no repeat items?

So I want to make a common event for a chest to be able to award one of say... 50 different items (blueprints to be exact), but to never overlap the items.


For example if someone opens a chest with this common event it awards a blueprint for a Tonic, but they'll never get that blueprint again from the common event chest. How would I do that? Alternatively if there's a plugin for that I'll take it. lol


*edit* The answer, thanks to Tsukihime. I'll more or less copy what Hime stated, but in an easier to read format. I have difficulty with scripts, so I'd like to help others who have the same difficulty.


Start by initializing a list of items somewhere using a script call. For simplicity I will say the items that we can get are 2, 4, 6, 8, and 12.


var list = [2, 4, 6, 8, 12];
$gameVariables.setValue(1, list);



The "var list" dictates the Item IDs of the items you wish to be able to be selected.


The "1" indicates the variable the list will be located in. In my case I used variable 31.


Now you've stored your list in variable 1. If you open the debug menu you can see a list.


Next, you will create your common event that will pick a random ID, add that to the party, and then remove the ID from the list.


var list = $gameVariables.value(1);
var numItems = list.length;
// pick random number
var index = Math.randomInt(numItems);
// gain item
var itemId = list[index];
$gameParty.gainItem($dataItems[itemId], 1)
// remove from list
list.splice(index, 1)
// update list again
$gameVariables.setValue(1, list)



The top line's "1" and the bottom line's "1" should match your variable list. In my case it was variable 31.


The "1" at the end of the line "$gameParty.gainItem($dataItems[itemId], 1)" indicates the amount of the item.


At this point you should create a conditional branch. On page 4 at the bottom you will see "Script". The script command you want is this:


$gameVariables.value(1).length === 0


If true, that means there are no items left to receive. The "1" indicates the variable list you chose. Again, in my case it was 31.


I hope this helps someone and helps to explain things that I had to use trial and error for.


Thanks for the answers, Tsukihime, and let me know if anything about this post concerns you. 🙂
I do this, actually, for specific key items that can be found in chest... Generate a number, have a bunch of nested if/else going something like:


if someRandomNumber = 1
if not hasTonicBluprint
get blueprint
end if
else
if someRandomNumber = 2
if not hasPotionBlueprint
get blueprint
end if
else
...etc
end if
end if


Assuming the pseudocode makes sense to you. You could also have an else on the if not has whatever blueprint so that you get some other random item, or show a message that the chest was empty.
I kinda understand that code, but wouldn't that just make it so.. say.. you "roll" a 56 which would be tagged to "Excalibur Blueprint" and get it. But if you opened a different chest and somehow "rolled" a 56 again you wouldn't get anything? That's what it looks like.
@Servidion


The easiest way would be to maintain a list of items that you could get, and then pick a random item from that list.


You can store lists inside variables using script calls.



Start by initializing a list of items somewhere using a script call. For simplicity I will say the items that we can get are 2, 4, 6, 8, and 12


var list = [2, 4, 6, 8, 12];
$gameVariables.setValue(1, list);


Now you've stored your list in variable 1. If you open the debug menu you can see a list.


Next, you will create your common event that will pick a random ID, add that to the party, and then remove the ID from the list.


var list = $gameVariables.value(1);
var numItems = list.length;
// pick random number
var index = Math.randomInt(numItems);
// gain item
var itemId = list[index];
$gameParty.gainItem($dataItems[itemId], 1)
// remove from list
list.splice(index, 1)
// update list again
$gameVariables.setValue(1, list)


You should also perform a check to see if there are any ID's left in the list.
Still learning scripting. How do I link an item ID to the variable list?


Are the numbers in 


var list = [2, 4, 6, 8, 12];


meant to represent the item IDs?


And how do I make a check to see if there are IDs left in the list?


*edit* After some trial and error I find that the "var list" I quoted does seem to represent the item ID.


Also figured out which "1"s I needed to change to my variable for it (1 was used a long time ago for my game).


How would I make it so it displays "empty" or gives gold or something when the list of items runs out?
@Servidion


Assuming variable 1 stores the list of items, in a conditional branch you can use a scripted condition


$gameVariables.value(1).length === 0


If true, that means there are no items left to receive.
It works! Took a bit to figure out, but it works!


Thank you very much! Couldn't decide how to distribute random blueprints and didn't really want them to be mob drops. Now I have my answer. 😀


Now I just need to find a nice way of having a chest respawn after an hour has passed without having "wait 999" a whole pile of times on a second page.

Original thread: https://forums.rpgmakerweb.com/threads/answered-random-chest-loot-with-no-repeat-items.60666/