Revisiting Death – Challenge Solutions

A few weeks ago we explored the power of an “Avoid Death” state, which allowed us to call events at the close of battle – powerful stuff, if a bit tedious to implement. We used it to keep track of a “kill 10 rats” type quest, but let’s explore a bit more what else we can do.

 

Bird Eater

The first challenge was to implement a random chance that an overpowered enemy appears after a bird dies. The easy (and way more fun) part is making the enemies, so go ahead and make your bird and your bird eater, then create a troop with, say, 2 birds and an eater. Add your battle event to make sure everyone avoid’s death in the battle.

Click on your bird eater, then click "appear halfway through." Now he won't be in battle until his presence is requested.

Click on your bird eater, then click “appear halfway through.” Now he won’t be in battle until his presence is requested.

We want to summon the bird eater, but only if two conditions are met: it hasn’t been summoned already this battle, and a 10% is satisfied. So we’ll set up 2-nested conditional branches, and if both conditions are satisfied, summon the bird.

Remember to kill your bird (by removing avoid death and adding death) regardless of whether the Bird Eater is summoned!

Remember to kill your bird (by removing avoid death and adding death) regardless of whether the Bird Eater is summoned!

Don’t forget to make an event page for each enemy! You might even use a global switch to ask if the Bird Eater has ever been fought – not just this battle. It’s a unique way to set up a boss fight!

Magic Points

And of course, at the end of each battle we can even change global variables as necessary, like adding magic points to the battle participants. First, use a variable to set the number of points you want to assign at the start of battle.

Manually setting the magic points for the troop can give you more control over magic leveling in your game.

Manually setting the magic points for the troop can give you more control over magic leveling in your game.

Just like with our Bird Eater, we might set some conditional branches inside our death events. Here, as it turns out, we don’t want an event to be called when any enemy dies; we want it to happen when the last enemy dies. So, when Bird 1’s HP drops to 0%, we’ll want to ask, is Bird 2 dead?

Again, the bird needs to die one way or another. We'll handle "end of battle" events inside the conditional branch.

Again, the bird needs to die one way or another. We’ll handle “end of battle” events inside the conditional branch.

Insides our conditional branch, we’ll increment the magic points of everyone who participated in the battle.

For every actor, we'll need to ask if they're in the party, and if they are, award them points.

For every actor, we’ll need to ask if they’re in the party, and if they are, award them points.

And that’s it! This will work as-is for a magic point system, but it feels a little tedious doesn’t it? Even if you’re afraid of using someone else’s script, there are certain little Ruby tricks you can employ to clean up your own code.

Additionally, this event system has one little quirk . It will apply magic points to everyone in your party, even if they didn’t show up to battle. So let’s clean this up nicely.

A Touch of Ruby

Rather than a dozen nested conditional branches to ask which actor is in the party, we can just run a for loop over the battle members. RPG Maker VX Ace allows us to access a list of players currently in battle with:

$game_party.battle_members

So the line:

for a in $game_party.battle_members

Just means that for each actor in the battle, we’ll do something. What is it we’ll do? Increment their magic point variable by the correct number, of course! Something like this:

RPG Maker VX Ace allows you to access things in script form unavailable in the trigger editor. Here's an example - we can actually ask who is in battle?

RPG Maker VX Ace allows you to access things in script form unavailable in the trigger editor. Here’s an example – we can actually ask who is in battle?

Let’s break that down:

  • id = a.id : for our actor, a, get its ID. Remember, the numbers next to anything in your database are the keys to the kingdom! Here, we’re using the ID as a way to track each actor.
  • var = a + 7 : if you look at the evented version of this script, you’ll notice that the variable tracking Nick’s magic points is 8, even though his actor ID is 1. No worries, this allows us to offset (so that Marcy, who is actor 2, will assign to variable 9).
  • points = $game_variables[7] : while the character we need to deal with changes dynamically, we’ve set the magic points at the start of battle in variable 7. So let’s get those too.
  • $game_variables[var] += points : this is where the magic happens. Take the correct variable (ie. “Nick’s Magic Points”) and increase it by the value of magic points we assigned at the start of battle. Close it out with end.

Since this is always the same script no matter who you’re fighting, you can and should move this into a common event and just call it in battle once every enemy is dead.

What you choose to do with these assigned variables is up to you!

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