(Answered) Random chest loot with no repeat items?

Servidion

Last Soul Keeper
Veteran
Joined
Mar 15, 2015
Messages
233
Reaction score
27
First Language
English
Primarily Uses
RMMV
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. :)
 
Last edited by a moderator:

taarna23

Marshmallow Princess
Global Mod
Joined
Jul 20, 2012
Messages
2,402
Reaction score
4,966
First Language
English
Primarily Uses
RMMZ
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.
 

Servidion

Last Soul Keeper
Veteran
Joined
Mar 15, 2015
Messages
233
Reaction score
27
First Language
English
Primarily Uses
RMMV
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.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
@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.
 

Servidion

Last Soul Keeper
Veteran
Joined
Mar 15, 2015
Messages
233
Reaction score
27
First Language
English
Primarily Uses
RMMV
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?
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
@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.
 

Servidion

Last Soul Keeper
Veteran
Joined
Mar 15, 2015
Messages
233
Reaction score
27
First Language
English
Primarily Uses
RMMV
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. :D


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.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,072
Members
137,578
Latest member
JamesLightning
Top