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.

Simple Event Based Variable and Item Operations (Blacksmithing Example)

This is somewhat of a beginner's tutorial for those that don't quite fully understand how to work with variables.

NOTE: This works for virtually all RPG makers from RPG maker 2000 to RPG VX

I helped someone recently make a simple blacksmithing system, so I'm going to guide you through step by step the uber simple process that requires no scripts.

Creating a common event to check for Items
You need to go to the database manager (the place where you edit actors, items, animations, skill, etc.)
There will be a tab named "common events".  Click it.  Think of a common event as an event that you can call over and over again from anywhere in the game.  Now name a new common event something like "Inventory Check". Basically our goal here is to create an event that checks our inventory for items that are needed for blacksmithing (or alchemy or whatever you want to do) and assigns the number of these items held in your inventory to a variable.

Now in this tutorial we'll just do one to save time and space.  Insert a new process, and have it be "Control Variables".  I use an item I created called "Iron", but you can use any item you want.  Take a look at the picture below to see how you should set everything.  Basically, what this does is sets the number of "Iron" in your inventory to the variable "# of Iron" that you specified at the top.  So if you had 2 Irons in you inventory, the value of # of Iron is now 2.

Click okay and we have all we need right now for the common event!  In the future you can do this same thing to check for whichever items you need to check for.

http://i292.photobucket.com/albums/mm4/ ... smith2.jpg[/img]

http://i292.photobucket.com/albums/mm4/ ... smith3.jpg[/img]

Creating an actual Blacksmith
Now we have to create an actual blacksmith.  Create a new event and make it look something like a blacksmith.

Have the first thing it does is call the common event that you just created (This is so it sets all of your variables to the correct values aka the correct number of items currently held in your inventory)

Next you can add in a message from the blacksmith, something like "This swords can be made from 2 Iron and it'll cost ya 20 Gold" (because blacksmiths don't work for free ya know) and give the player a choice to choose Yes or No. 

Now under the Yes line, we are going to start using conditional branches to check if the player actually does have the materials require to make the item.  Create a Conditional Statement.  You're going to want to click the Variable bubble and make it be the # of Iron Variable.  Then in the dropdown box below it select Greater than or equal to, and select a constant of 2.  What this does is checks to see if your variable # of iron has a value of 2 or greater.  Leave the box that says set handling when conditions don't apply, because this is going to allow us to have event processing for when the player does not have 2 or more Iron (we can leave a message like "You do not have 2 Iron").

http://i292.photobucket.com/albums/mm4/ ... smith4.jpg[/img]

Now if all we needed was for the player to have 2 Iron, we'd not need any more Conditional branches, but since we also need 20 gold, we have to check for that as well!  Most of the time you're going to be checking for many things, and you'll need additional Conditional branches inside of each branch for each additional thing that you need to check for.  Basically think of it in this grammar:  "If player has 2 or more iron, then ->  If player has 20 or mole gold, then ->  Sucess!  Add 1 sword, take 2 iron away, take 20 gold away."

So between the conditional branch you just made and the Else line, make a new conditional branch.  This time go to the 4th tab and select the "Gold" bubble, and check to see if the player has 20 or more gold.  Leave the ELSE handling conditions box checked this time as well.

Now between your newly created branch within a branch and your new Else created from that branch, you can create your processing for a succesful smelting and payment!  Have a message telling the user it was a succes, then change your inventory accordingly.  For the else condition here you might want to let the player know that they did have enough Iron, just not enough Gold.

http://i292.photobucket.com/albums/mm4/ ... ksmith.jpg[/img]

And that's it!  Short and sweet, but from this template you should be able to create much more sophisticated blacksmithing operations (or crafting or alchemy or whatever you want in your game!)

Demo:  http://www.megaupload.com/?d=JPY7I344

Edit:  Also, you need to download the Variable fix script from the scripts section of this site (stickied).  You'll notice that if you don't the game will error, because by default variables don't even work worth a shit in rmvx.
 
Hey this is sweet, I don't think there is a single RPG maker that that's not perfect for!  :thumb:

8/10 - Good but you should say that you can do this in all rpg makers!!! :tongue2:
 
Ah yes... the genius programmers over at Enterbrain didn't know how to program the variable functionality apparently (even though they've done it for how many rm's now?)  So you'll notice in my demo there's a add-in script called "variable fix".  You gotta paste that into your scripts in order to get variables to function properly.  You can also find that script as a sticky in the script sections (called something like variable fixes)
 

tuti05

Member

good so i can finally make a locked door that you need a key for. Or a guy that wants to sell you a boat and checks to see if you have money. and i can do bribes too!!!!! woooooo!  Thanks a lot
 

RuGeaR

Member

brettlee25":5eb5owwp said:
Ok i did everything right but i keep getting this error i have gon over and over everything but i don't know a thing about scripting can you please help

Brett

http://bb.xieke.com/files/erroe.png[/img]



EDIT

It's ok I had a scripting problem with my variables but i got that fixed

uhh... hw did u fix dat? i got the same error?

EDIT
nvm... i got it fixed too... =D
 

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