Variable Affected Skills
hiddenone
by
hiddenone
on
June 9, 2022
May 31, 2022

Variable Affected Skills

Variable Affected Skills
by

hiddenone

on

June 9, 2022

Using the same skills over and over in battles without them ever changing can make battles end up feeling boring, so let’s take a look at how we can add some interesting effects to skills by keeping track of how many times each skill is used and modifying the skill’s damage based on that.

To get these effects we’ll be including some extras to each skills’ damage formula. This is meant for actors that the player will always have control of, due to how the engine decides on which skill to use in battle these types of damage formulas shouldn’t be used for enemies or actors that have the auto-battle trait (or if you use a plugin that majorly changes how the A.I. connected to battles works). If you want enemies or auto-battling actors to have skills affected by variables you’ll want to set up common events for the variable changes instead.

Fire+

Let’s keep our first skill pretty simple: a fire attack that adds 1 to the damage each time it is used. That means that if Priscilla uses the skill 15 times then the damage will be the base amount + 15. While testing we’ll remove any costs for using the skill, set it to Certain Hit, and set the damage Variation to 0% so that we can make sure that things are working right, since we can always add a cost or adjust the Hit Type and Variation later on.

We’ll keep the base damage simple for this example by setting it to 100, so that it will be obvious when it is increased. Next we’ll need to choose a variable that we’ll connect to this skill (variable 1) and add it to our base damage, giving us 100 + v[1] as our formula. This seems like it should work, but if we don’t change our variable anywhere our Fire+ skill will actually do 0 damage when used. That’s because by default our variable isn’t set to anything so the engine ends up thinking that the whole formula is undefined and defaults to 0 damage. If we set the variable to 0 at the start of the game, then our skill would do 100 damage since the added v[1] is 0.

All of that is good to know, but we’re missing the important part of the formula: increasing the variable. To do that, we need to add in some code to increase our variable by 1 before the actual damage part of the formula. If we check the MV/MZ Script Call sheet, we can see there are two ways we can write out the code:

$gameVariables.setValue(1, ($gameVariables.value(1) + 1));

or

v[1] = (v[1]||0) + 1;

Which tells the engine to add 1 to the variable’s current amount. Either works, so let’s grab one of them and add it to the start of our formula, giving us the final version: v[1] = (v[1]||0) + 1; 100 + v[1] .

With our damage formula ready, our skill ends up looking like this:

Then we can playtest and make sure it’s working as intended. Priscilla will use the Fire+ skill every turn, which should increase its damage by 1 each time.

After a few turns, we can see that it’s working and the damage is increasing each time it is used.

Of course, there are some issues that you’ve probably already spotted if you aren’t using this idea for a single actor’s skill. If we were to connect a specific variable to every skill we make then we’ll end up needing tons of variables devoted to just skills. And if we let multiple actors use the Fire+ skill then the variable will increase no matter who used it, which may not be how you want the skills to work. We’ll cover how to deal with those situations at the end of this tutorial, so keep reading!

Water+

We can now increase the damage of a skill each time it’s used, but what if we wanted Priscilla to learn a new skill if she uses a certain skill enough times? For Water+, let’s have it teach Priscilla Wave+ after she’s used it 5 times. The skill itself will be set up a lot like Fire+ for testing, the main difference being that this skill will call a common event to run once the damage has been dealt.

We have a new variable being added to this skill, using the other option we talked about earlier, and the damage being a basic 100. We don’t need anything else in this formula, since we’ll be checking and adding the new skill through the common event.

Our common event needs to check our variable in a condition branch to see if it is equal to or more than our target number (5 uses). We need to set it up to check if the variable is more than 5 since the common event won’t run if the skill is used at the end of the battle, so if we had it set to check if the variable was exactly 5 but the battle ended our unlucky player would never get the Wave+ skill. Of course, we don’t want the skill message to play each time Water+ is used after 5 uses, so we can nest another conditional branch inside the first one to check if Priscilla already knows Wave+ or not. If she does, then nothing will happen.

The Wave+ skill itself is pretty simple in this example, with it hitting all enemies instead of just 1. We could set it up to learn another skill if we wanted, leading to skills that chain together sort of like a skill tree without a separate tree map.

Then we just need to playtest and make sure that Priscilla learns her new skill after using Water+ enough times.

But what if we didn’t want our heroes to learn the skills mid-battle, and instead any new skills were gained after the battle? Then instead of having the common event teach the new skill, have it turn on a switch that will activate a second common event with its Trigger set to Autorun and tied to that switch. Once the battle ends that common event will play, teaching the skills that were learned (just make sure to turn the switch Off at the end).

Thunder+

For our Thunder+ skill, let’s give it an interesting effect: every third time the skill is used, it will do 5x the normal damage. That means our player will want to keep track and plan when they use Thunder+, making them plan out their battle a bit more.

Our skill starts much like the previous ones, where we need to start the damage formula by increasing the skill’s variable by 1.

Once the variable is increased, we need to set up a conditional branch to see if the variable equals 3 (meaning it’s the third time the skill is used) and if it is then the damage is 500. If the variable isn’t 3, then it will do the default damage of 100. We can write that out as if (v[3] == 3) {500} else {100} , but there’s a problem: if the skill is used more after that and increases the variable more, the 5x damage won’t happen again! So before we do the 500 damage, we need to reset our variable by setting it to 0 with v[3] = 0; .

So our formula ends up as:

v[3] = (v[3]||0) + 1; if (v[3] == 3) {v[3] = 0; 500} else {100}

When we playtest, we’ll find the normal 100 damage done the first two uses…

And our 5x damage done the third use! If we kept using it, then every third use would be that special 5x damage.

Tying uses to Single Actor-Specific Variables

Okay, now that we understand how to do some cool things with variables in skill damage formulas, let’s take a look at how we can condense things so that we don’t need a separate variable for each skill.

Variable in damage formulas can check arrays just by writing v[n][A] (with A starting at 0 for the first number in the array), so if we start the game by setting a variable to an array full of 0s equal to the number of variable-affected skills then we can just match up different skills to the different array numbers.

We can also change our skills to track a separate variable for each actor by adding some conditions to the start of the formula that changes which variable is read for different actor Ids.

To see that in action, let’s make an Improved Fire+ skill. The damage formula will stay mostly the same, though instead of 100 + v[1] we’ll be rewriting the variable part to be v[n][0]. That will take the first number in the array and add it to the base damage.

For this example, let’s have both Priscilla and Michelle be able to use Improved Fire+. That means we’ll need to check if the actor Id equals 2 (meaning it’s Priscilla) and if it is set n to her variabler (1), using if(a.actorId() == 2){var n = 1}; , and then doing the same to check for Michelle’s actor Id and connected variable.

That gives us:

if(a.actorId() == 2){var n = 1}; if(a.actorId() == 4){var n = 2}; v[n][0] = v[n][0] + 1; 100 + v[n][0]

If we were planning this out from the start of our games’ development, we could match our actor Ids to the same numbered variables, meaning we could replace the conditions with var n = a.actorId(); instead of the conditions, but if we’re already using those low-number variables elsewhere in the game then the above conditions is probably easier.

In-game, we’ll be able to see that if Priscilla uses the skill each turn then by turn 5 she’d be doing 105 damage.

While Michelle hadn’t used the skill until turn 5, meaning she hadn’t been improving the skill so only did 101 damage.

Being able to separate the skill use by different actors gives us a lot more options for interesting skills. Maybe only certain actors can learn new skills, even when all of the party members can use the skill. With this knowledge, what type of skills will you add to your games?

Recommended Posts