Yanfly Damage Formula (Multiple Else If Factors)

Intret

Reality Chronicler
Member
Joined
Apr 19, 2018
Messages
7
Reaction score
3
First Language
English
Primarily Uses
RMMV
I'm trying to set up a skill that has a random chance of doing extra damage based on a variable number. I was able to get to this point without it just shutting down the entire sequence.

<damage formula>
value = a.atk * 4 - b.def * 2;

if ($gameVariables.value(87, 2)) {

value *= 3;

} else if ($gameVariables.value(87, 3)) {

value *= 5;

} else if ($gameVariables.value(87, 4)) {

value *= 7;

} else {

value *= 1;

}
</damage formula>

But now all it does is return a damage value of 0 every time I use the skill it's attached to.
 

TSR

The Northern Frog
Veteran
Joined
Nov 14, 2019
Messages
279
Reaction score
244
First Language
French
Primarily Uses
RMMV
Hi, you should write it:
Code:
<damage formula>
value = a.atk * 4 - b.def * 2;

if ($gameVariables.value(87) === 2) {
  value *= 3;
} else if ($gameVariables.value(87) === 3) {
  value *= 5;
} else if ($gameVariables.value(87) === 4) {
  value *= 7;
} else {
  value *= 1;
}
</damage formula>
 

Creative Ed

Veteran
Veteran
Joined
Sep 16, 2013
Messages
318
Reaction score
331
First Language
Portuguese
Primarily Uses
RMMV
You can actually do it in a more simpler manner. You don't need a game variable for an effect like that. You could create a variable just for this skill.

Code:
<damage formula>

extraDmg = Math.floor(Math.random()*7));  //random number between 0 and 7. You can put another value.


//formula

(a.atk * 4 - b.def * 2) * extraDmg;

</damage formula>
 

Intret

Reality Chronicler
Member
Joined
Apr 19, 2018
Messages
7
Reaction score
3
First Language
English
Primarily Uses
RMMV
Thanks for the help. And mat.random would work in most regards. I just needed it to match a certain variable so
it lined up correctly with the common event connected with it. I appreciate the advice.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

On my journey of character rework: I had this character, she was meant to be just a princess that joins your party. And at long term she was just uninteresting... So I tweaked her to be a rebel agaisn't the royalty before meeting up with the party.

Quick tip for any other ametuer pixel artists! When trying to create a colour palette, enabling Antialiasing can speed up the process of creating different shades! Just place your lightest colour and your darkest colour next to each other, select both pixels, and stretch it out!
Revolutionizing the JRPG Industry: Knocking on Doors.

Take that, murderhobos.
Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.

Forum statistics

Threads
106,054
Messages
1,018,578
Members
137,843
Latest member
Betwixt000
Top