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.
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.
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.
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!
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.
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?
Insides our conditional branch, we’ll increment the magic points of everyone who participated in the battle.
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:
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:
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 : 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!