Main Menu
  • Welcome to The RPG Maker Resource Kit.

Random Item From Treasure Chest Using Events

Started by Silne30, February 21, 2010, 11:34:13 PM

0 Members and 1 Guest are viewing this topic.

Silne30

Hello there again. This is your local Silne30 speaking and the process I am going over today will be if you want to open a chest but get random items. Now, scripting is not my forte. I asked my buddy Kain Nobel (you may know him) about a random item event and he told me in terms of scripting. He may as well had been speaking Flanknard to me because I couldn't understand it so I kinda came up with my own using an event and forks and it is actually really simple. First you start off with the number of items that you want to have to choose from. For all instructional purposes we will do 3.

Step one: We will go to Control Variables on the first page of your event editor. Now if you don't know where that is, take a look at your help file in RMXP and then refer back to this post. Once you do that we will give a new variable a name that we will remember. For my tutorial I will call the variable Random Item 1-3. I used the (1-3) because for this tutorial we will use items one through three in the database. Now for your operation we are going to Set and the operand will be random and you place the first number as one and the last as 3. What that will do is when you access the event via action button, the event will randomly set the variable Random Item 1-3 to a value that will either be 1, 2 , or 3.


Step 2: Now that we have what the value of Random Item 1-3 will be we have to use conditional branches. They basically mean if blah blah blah happens then do blank. So the first conditional you open up will bring you up to a page that has switch, variable, and some other options. So since the item in question is a variable (Random Item 1-3) select variable. Pick Random Item 1-3 from the list and then set the little drop-down to equal to and put a 1 where it says constant. So now the computer is thinking "If Random Item 1-3 is one...now you have to tell it what to do. But before you leave the conditional branch screen you are going to click the else case box at the bottom. The reason you are doing that is because you have other options as to what Random Item 1-3 can be.


Step 3: Now that we have our first conditional branch you will notice two things. There is a space under the condition and then there is a space under where it says else. Under the first space (Not the else) put what you want the first item to be. So here you can put a message like "You received potion." And add one potion to your inventory. Now that you have done that, under the else you are going to create another conditional branch. In this you will do the same as the first time but instead of setting the equal to to 1 it will be two. Make sure the else case is still checked and fill what item you will get if it is a 2. So this time it can be "You received an elixir."For the last else case you will create one more conditional branch and set the equal to to 3 but this time there will be no else case because we only have the options of 1, 2, or 3. Fill out the last item and then try your chest out. Should work pretty smoothly.

Your code should look something like this:[spoiler][/spoiler]

Well, I hope this helps. My first tutorial ever. If you have any questions or if I explained something wrong...please let me know. Thanks for your time.  ;D

There is no reason to procrastinate and put things off until tomorrow. For what is today but yesterday's tomorrow.

Mr_Wiggles

#1
Nice little tut, could help some one out.

but in your picture, you can have the random variable just go between 1 - 3 or in the amount of the items that can be received.  I also noticed that when you set your random variable it goes past the conditional branches (you have 3 items and you have 4 numbers that can be chosen).  Which is nice if you wanted there to be a chance of not getting an item from the chest.

Still this is neat little tut, and hopefully you can make some more.
[spoiler]
METALFRESH is a paint contractor that specializes in refinishing metal and vinyl siding. We paint metal buildings as well as siding on homes.

We also

    Refinish decks
    Do custom interior painting
    Strip wallpaper
    Refinish cedar siding
    Metal front doors and sidelights
    Metal garage and service doors
    Grained fiberglass doors

    If your structure is *RUSTED *FADED *CHALKING *IN NEED OF COLOR CHANGE, we can fix it with a guarentee!

northern Illinois and southern Wisconsin.

http://metalfreshcoatings.com

[/spoiler]

modern algebra

#2
I think he's got it right, actually Mr_Wiggles. I'm pretty sure the range of a random number generation is min <= integer < max, so a generation from 34...37 can only produce either 34, 35, or 36. Anyway, it's a nice tut sline. A little basic, but I know a lot of new users will get a lot out of this tutorial - one of the first tuts I ever read (for RM2k3) explained how to do this very thing, not that I had any idea how to use variables way back then :)

Silne30

#3
Thanks. I am glad you like it. As my knowledge grows I hope to put some more advanced tutorials out. Yeah I added the fourth option for the number for my game but it wasn't supposed to be in the tutorial. Thanks for pointing that out.  :lol:
There is no reason to procrastinate and put things off until tomorrow. For what is today but yesterday's tomorrow.