# How do I turn this complicated formula into a state?

#### DeltaLime24

##### Villager
Okay, bottom line here, I have a bit of a mess on my hands. I want to use a formula to create a skill that applies an "Inverted" state to "Invert" the statistics of my characters for 3 turns (e.g. 70 atk at lv 50 would become 255-70 = 185 and 140 atk at lv 100 would become 510-140 = 370 etc)
As you can tell, such an idea is a pain to implement in RPG Maker MV, as is most complex mechanics. Below is a formula I made by butchering the damage formula of a skill:

a._paramPlus[2] = 2.55 * a.level * 2 - (a.atk*2);a._paramPlus[3] = 2.55 * a.level * 2 - (a.def*2);a._paramPlus[4] = 2.55 * a.level * 2 - (a.mat*2);a._paramPlus[5] = 2.55 * a.level * 2 - (a.mdf*2);a._paramPlus[6] = 2.55 * a.level * 2 - (a.agi*2);a._paramPlus[7] = 2.55 * a.level * 2 - (a.luk*2);0

It works fine, but changes the stats permanently. A second inversion seems to not give the character their original stats.

Thank you for reading through my post.

#### Naveed

##### Veteran
If you're using Yanfly's Buffs and States Core, you can create the invert state and use these notetags in that state's notebox:

Code:
``````<Custom Apply Effect>
user._paramBonuses = user._paramBonuses || [0,0];
var max = Math.round(5.1 * user.level); // Formula for defining max value
for (var i=2; i<8; i++) {
var param = user.param(i);
var diff = max - param; // Difference in stat value
user._paramBonuses[i] = diff;
user._paramPlus[i] += diff;
}
</Custom Apply Effect>

<Custom Remove Effect>
for (var i=2; i<8; i++) {
user._paramPlus[i] -= user._paramBonuses[i];
}
user._paramBonuses = undefined;
</Custom Remove Effect>``````
The bonus stats should revert back once the state is removed. Note that when calculating the original stat, this considers all effects that could affect the stat, which are the base stats, equipments, param rates and buffs/debuffs.

Last edited:

#### DeltaLime24

##### Villager
Thanks for the notetags, I did have Yanfly's Buffs and States Core convieniently enough. One issue though, how do I stop it from affecting HP and MP? I'm keeping those at a constant rate for specific reasons.
Another thing about MP specifically, it returns a non-existant number, so I haven't been able to test it. Checking the menu out of battle causes a fatal error with this installed.
Yet another error that occured was that I cannot access the regular attack or guard as well as any attack that required MP.

Edit: on closer inspection of the fatal error when opening the menu, it seems the notetag you suggested is actually an infinite number.

Does this line affect the stats it selects?
for (var i=2; i<8; i++)

Last edited:

#### Naveed

##### Veteran
Oops I made a mistake in the original one where I forgot to reference the index of the array. Fixed it and it should work now (edited the original post).

#### DeltaLime24

##### Villager
Okay, now at LV 50 all stats are 255 and at LV 5 are 26. It appears to just change every stat to the maximum. I think I found what makes that happen, but I'm shaky on my javascript.
For whatever reason, these lines aren't working:

var param = user.param(i);

var diff = max - param; // Difference in stat value

#### Naveed

##### Veteran
Ah I see, I was adding up the difference between the stat and the max, which caused the stat to be max. What I should have done was set it to the difference and not add the difference, then store the difference in paramPlus to restore it later.
This was a bit more complicated than I thought, but it's still possible.

Try this:

Code:
``````<Custom Apply Effect>
user._paramBonuses = user._paramBonuses || [0,0];
var max = Math.round(5.1 * user.level); // Formula for defining max value
for (var i=2; i<8; i++) {
var param = user.param(i);
var diff = max - param; // Difference in stat value
var temp = param - user._paramPlus[i];
temp = diff - temp;
user._paramBonuses[i] = temp - user._paramPlus[i];
user._paramPlus[i] += user._paramBonuses[i];
}
</Custom Apply Effect>

<Custom Remove Effect>
for (var i=2; i<8; i++) {
user._paramPlus[i] -= user._paramBonuses[i];
}
user._paramBonuses = undefined;
</Custom Remove Effect>``````

#### DeltaLime24

##### Villager
Works perfectly now. Thank you for helping. I'll toy around with some of the stuff you put in this.

### Latest Profile Posts

So I'm having issues with my steam account... so I can't use MZ right now, so I can't work on my game until its solved, so it be harder to be ready for 31... guess I'll get ice cream
Motivation! Inspiration! There you are. I was worried you guys weren't going to show up today. Let's get this thing going!
Made these new little isles yesterday, to test my new tiles. Guess they're look pretty chill...
Made a lot of progression today with my next chapter. It helps that I wrote an outline of what will happen.