A few weeks ago we discussed the power of the damage formula bar in a skill, and two challenges were issued.
Marcy Mage has a slightly different mark she applies. Any damage the enemy takes by any of Marcy’s friends (or Marcy herself) will be measured against that enemy’s magic defense – even physical damage. How do we do that in the formula bar?
Marcy Mage just leveled up her mark. Now, any damage the enemy takes is does fire damage, such that it considers the target’s fire resistance or weakness (great against those stupid ice imps). How do we do that in the formula bar?
So let’s dig in!
You can probably guess based on the last post that our damage formula is going to be a ternary operator. And you might even guess that the first part, the question, is the exact same as before. That’s right:
b.state?(25) ? x :y
And in fact, “Y” should just be the normal damage done by the skill. It’s what happens when the state isn’t on. All we need to do is fill in for x.
The answer is to just change the stat examined. So, if we look at our damage formula, we’ll say that we replace the enemy’s defense with magic defense. Something like:
b.state?(25) ? (a.atk*4 - b.mdf*2) : (a.atk*4 - b.def*2)
And that’s it!
A bit more involved this time; first, we’ll need the number for your fire element. Remember, those little index numbers in the database are always the key! We ask what an enemy’s resistance is to an element with:
This returns a decimal corresponding to the percentage you might set in your enemy page. For example, the default “Slime” takes 200% ice damage, so b.element_rate(id number for ice) would be the same as saying “2.”
See where this is going? The following answer will give you the upgraded mark which takes into account the target’s fire resistance:
b.state?(25) ? (a.atk*4 - b.mdf*2)*.b.element_rate(3) : (a.atk*4 - b.def*2)
And that’s it! Follow instructions – Marcy’s mark doesn’t have this upgraded ability until later in the game! Let’s say she gets access to it at level 10. Uh oh, now we have three possible options:
- The enemy hasn’t been marked
- The enemy has been marked, and Marcy is level 10 or higher
- The enemy has been marked, and Marcy is not yet level 10
We need three possible damage formulas, not two. Let’s follow the logic.
Does the enemy have mark? If no, do regular damage. If yes, is Marcy level 10 or above? If no, do magic defense damage; if yes, also do fire damage. To avoid repeating myself so many times in a line, I might actually want multiple lines of code. To do that, use “;”. Something like:
mult= $game_actors.level >= 10 ? b.element_rate(3) : 1; b.state?(25) ? (a.atk*4 - b.mdf*2) * mult : (a.atk*4 - b.def*2)
So that’s actually two lines of code. First, assign the variable “mult” based on whether Marcy (who, in my example is Actor 9) has reached level 10 or not. If she has, mult is our enemy’s fire resistance rate, otherwise it’s just 1. Then, if the mark is applied, attack using magic defense and apply the mult (meaning just multiply by 1 if Marcy isn’t level 10 yet); if the mark isn’t applied, do normal damage.
One final problem. This line is too long for the bar! So, we’d likely need to add it into our script section, and then call the function from our formula bar.