Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Random unique items from chests

Hey, if anyone could help me with this I'd be very thankful.
I'd like to request a script that, when the player opens a chest/trunk/or other area where items can be taken, a random item from a list is given. And once the item has been given, it can't be given again.
So if the hero opens a treasure chest and gets an Ivory Mask, (s)he'll never be able to find it again. It's sort of a tiny minigame/sidequest I have planned for my game.

Thanks.
 
You don't need to do actual scripting for this. I'll show you a way to do it with events and hopefully you liek this method.

http://img.photobucket.com/albums/v502/ ... elping.png[/img]



What you do is make a variable operation and set it's random number to be however many items you are making available randomly.

Then make a conditional branches for all the items and the conditional branch should reference the same variable operation, simply designate different numbers.

Now this is where you could do it in different ways depending on how you want it done. I made a conditional branch within the conditional branch that checks to see if you already have the item, if you do then it will not give you that item if it's designated number was randomly chosen.

Let me know if this efficiently gets doen what you need to be done. If not then give me more detail and I may be able to put together something that works better for you.
 

Anonymous

Guest

There's a less labor intensive way to to this:

http://img.photobucket.com/albums/v226/ ... 01642c.png[/IMG]

And, so that you can copy and paste it, here's the script code:

Code:
i = $game_variables[1]
$game_party.gain_item(i, 1)
$game_variables[1] = $data_items[i].name

Replace the first and third 1 with the number of the variable you want to use for the first chest. Hold on, I'll work up the whole system and edit it here.

Also, replace the random with the range of numbers of items you want to use. I used 0-10, which is actually a problem, since 0 would cause an error. :P So use 1-10 if you're going to copy this for testing purposes.

EDIT: Okay, made a demo for you:

http://www.rmxp.org/ccoa/Project4.zip

In order to specify which items you want to use, look at the autorun event in the upper left corner, and change this call script:

Code:
$items_array = [1, 2, 3, 4, 5]

To the numbers of the items that you want (as many as you want, but be aware if you make more chests than there are numbers, the player will get an error opening the excess one(s)).

Also, if you'd rather not use variable 1, change this line:

Code:
$game_variables[1] = $data_items[i].name

To the number of the variable you want to use.

This can be spread out over as many maps as you want, but make sure that autorun event is run before the player could open any chests.

Hope that helps you!
 
Sorry for rather late reply, but I lost internet connection when the somewhat rescent extreme hot weather actually melted a few lines...

umm, i'm unable to get the demo, but i've copied the posts to my computer incase I'm unable to get back online again.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top