LegacyCrono
Member
By LegacyCrono
Hello, there.
Before starting, I would like to say that I hate Internet Explorer. I wrote this tutorial two hours ago, but IE crashed and here am I, writing it all over again. I really hope that you enjoy reading it! :angel:
- First words - The Note
Most of you guys probably doesn't even know about that, but RPG Maker VX has introduced a very interessing - and useful - feature. When you open your project's Database, you'll find a text box where you can write random/dumb/useful stuff. You can use it to write "to-do lists" or something, but I've found another use for it.
Sometimes, when scripters are coding a new system, we have to create new data, that we usually put directly on the script. Instead of doing that, we can write this extra stuff on the Notes. When used at its fullest, the Notes are very powerful! I've made three examples that'll hopefully make you understand what I mean.
- A handy piece of code
I'm using this script to help me working with Notes. Paste this right before the Vocab module. This will add some handy functions to RPG::BaseItem. You might want to add those to RPG::Enemy and RPG::State, as those also have Notes. Simply make a copy of this script and change "BaseItem" to "Enemy". Make another copy and do the same for "State". :wink:
[ruby]#==============================================================================
# RPG::BaseItem  Note extension
# Â >> By LegacyCrono
#==============================================================================
Â
module RPG
 class BaseItem
 Â
  # Return if the marker exists on this object
  def marker?(str)
   return @note.upcase.include?(str.upcase)
  end
 Â
  # Return how many times the marker appears on this object
  def marker_times(str)
   return @note.upcase.scan(str.upcase).size
  end
 Â
 end
end
[/ruby]
- Example A - Special Skills
The first example will teach you how to create skills with special effects. It's a preety simple example, and will help you to understand the "marker" concept I'm using. You'll need the RPG::BaseItem Note extension I've posted, so be sure everything's working.
First, let me introduce you to "markers". When you flag an item/skill/etc with a special property on the Note, I call this flag a "marker". A "marker" on a Note is just a word. There's nothing special on it. The script will read the markers and do the necessary procedures.
Well, let's start by making some Skills on the Database and marking them. Make a new project or open an existing one. Head to the Skills tab at the Database and make three new skills. The first skill will reduce the target's HP by half. The second will damage (or recover) both HP and MP of the target. And the last skill will do both. Don't worry about those effects for now, just make the skills as usual.
We're done, here. Let's move to the scripting part.
At the Game_Battler script, search for def make_obj_damage_value(user, obj). This is the method that calculates the damage. There's a lot of damage calculation there, but we won't mess with it. After the line damage = apply_guard(damage), put the following code:
[ruby]damage = self.hp / 2 if obj.marker?("halve_hp")
[/ruby]
Preety simple! This line will change the damage to half of the target's HP value if the "obj" (it could be a skill or an item) has the marker "halve_hp" (you should change that depending of what marker you used at the skills).
Ookey-dokey. The next is the "hp_and_mp" marker. We'll remove the following code and put another on its place:
[rgss]if obj.damage_to_mp Â
 @mp_damage = damage
else
 @hp_damage = damage
end
[/rgss]
We need to check for the marker. Here's the updated code:
[rgss]if obj.marker?("hp_and_mp")
 @hp_damage = damage
 @mp_damage = damage
elsif obj.damage_to_mp Â
 @mp_damage = damage
else
 @hp_damage = damage
end
[/rgss]
If you want to, you can make the MP damage be smaller than the HP damage (e.g. 1/4), as MP is usually much lower than HP. Well, the finished code should look like this:
All done, boys and girls! Test it, and you'll see that it works. Three Special Skills, made easily! It should work with other Battle Systems too, depending of how they were coded...
Try making new Special Skills! Using multiple markers in a single skill can result on funny effects, so experiment a lot. If you have some RGSS acknowledge, you can make many different effects with ease. If you know nothing about RGSS, don't worry! Ask us for help and we'll be glad to lend you a hand. But you should try making them by yourself: it's not that difficult!
- Example B - Code Container
This might be a preety advanced example. Give it a try, but you might have difficulty if you know nothing about RGSS.
Well, I've found that Notes are useful to keep codes too. You can write RGSS there and execute it where you find it suits better, using eval(). Damn, you could even code a whole game there! Anyway, we'll do something more simple, okay?
Let's begin, then. Pick two items of your choice. I've choosed "Potion" (ID 001) and "Elixir" (ID 008). Don't worry about the IDs, they doesn't matter. We'll code some special behaviour for them at the Note.
That's what I'm going to do: the Potion will be displayed green at the Item menu (anywhere else it'll be white). Preety simple stuff. The Elixir will not display how many of it you have, but will show "MAX" when you got 99 Elixirs. That's easy, too.
I'll not explain the coding for you, but here's the code that'll be put at the Note.
Potion:
[rgss]if $scene.is_a?(Scene_Item)
self.contents.clear_rect(rect)
self.contents.font.color = Color.new(0, 255, 0)
draw_icon(item.icon_index, rect.x, rect.y)
self.contents.draw_text(rect.x + 24, rect.y, 172, WLH, item.name)
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
end
[/rgss]
Elixir:
[rgss]rect.x += 128
rect.width -= 128
self.contents.clear_rect(rect)
if number >= 99
self.contents.draw_text(rect, "MAX", 2)
end
[/rgss]
Alright, this part is done. Let's head to the scripts, them.
Actually, all the coding is already at the Notes, but we just need to execute it. We'll be using the following code at the method draw_item(), at the script Window_Item. Put it right after the self.contents.draw_text(rect, sprintf(":%2d", number), 2) line:
[rgss]eval(item.note)
[/rgss]
What, is that all? Of course not, you need to save and test it, remember?
Good, good! Now you should try making your own stuff. Think outside the box: there's a lot of stuff you could make using only the "Code Container" idea. The next example is a good use of this concept, so you should check it out.
- Example C - Jukebox
This is a very basic example that uses the "Marker" and "Code Container" concept to make a Jukebox/Sound Test thing.
Open a new project, or an existing one. Make a new item, and name it as you like. Make it non-consumable and set "none" as target. At the Note, put the following code:
[rgss]#use_code
$data_system.title_bgm.play
[/rgss]
What are we doing? Simple: first we used a marker, "#use_code". When using the Note for scripts, you MUST use the "#" or it'll give you an error. This symbol is used on Ruby/RGSS to create comments that aren't executed. This marker will be checked when the item is used. If it exists, the code is executed. Then, it'll play the Title screen BGM. Woohay!
What next? Let's head to the scripts. At the Scene_Item script, jump to def use_item_nontarget (it's the last method). After the line Sound.play_use_item, put this code:
[rgss]eval(@item.note) if @item.marker?("#use_code")
[/rgss]
This will execute the Note code if the marker is found. Done!
Well, that's all for now. I've barely spoken of all the possibilities, so you should find out by yourself what you can do with the Note. If you need further help, just ask it and we'll be happy to give more instructions. :thumb:
SEE YA!!!!!