Healing Variety

Reddit user kuroiryu146 is extremely thoughtful; he’s created a common event that heals all party members after every battle. He also wants to restore some amount of MP to each character, based on their class. We can put this right in our event using a script call. We’ll use a loop, and a case-statement in that loop.

Building The Loop

RPG Maker already provides you with an array of all of the people in your party. It’s called $game_party.members, and it will return a list of all actors in your party. Unless you’re in battle, then it will return a list of all actors currently in battle.

So to make a loop in Ruby, all we do is use the following syntax:

$game_party.members.each{|actor| }

In between the curly braces, after |actor|, we tell the loop what to do for every member.

Building the Case Statement

Each actor has an attribute called class_id. This is an index into your list of classes. Make sure you know the number for each class, you can find it easily in your database:

The number you need is next to the class name. In the default, 1 is soldier, 2 is monk, etc.

The number you need is next to the class name. In the default, 1 is soldier, 2 is monk, etc.

A case statement is a bit of logic that does different things depending on what a particular item equals. Here, we want to do different things depending on what the actor’s class_id is. If it’s 1 (Soldier), we don’t want to give them any MP. If it’s 2 (Monk), we want to give them a flat 50 MP. If it’s 3 (Paladin), maybe we only give them 25 MP. The case statement would look something like this:

case actor.class_id
     when 1
          actor.mp += 0
     when 2
          actor.mp += 50
     when 3
          actor.mp += 25
end

So putting it all together, our script looks like this:

$game_party.members.each{|actor|
     case actor.class_id
          when 1
               actor.mp += 0
          when 2
               actor.mp += 50
          when 3
               actor.mp += 25
     end
}

One Last Addition

Class 4 is our spell-blade. Suppose we wanted to always give him 50% of his maximum MP back. This is also easy! Just add the following to your case statement, before the “end”:

when 4
     actor.mp += actor.mmp * .5

Have fun!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s