Deagron

Veteran
Veteran
Joined
Aug 14, 2020
Messages
42
Reaction score
6
First Language
French
Primarily Uses
RMMV
Hello, I hope my issue is on the right thread.

I've been doing my project smoothly for now, and came across an issue with a skill that checks the hp of the target to increase its base damage.

My damage formula works correctly as I tested it on my usual skills, though it's a bit lengthy since variance was too big (the formula is inspired by Dragon Quest 8's damage formula). Here it is without the hp mechanic :

dmg = ((a.mat*0.7)*(a.level*0.035)) + ((a.mat*0.25) + ((a.level/70)*55)) - (b.mdf/6) ; rge1 = dmg-((dmg/16)+1) ; rge2 = dmg+((dmg/16)+1) ; dmg = Math.floor(Math.random() * (rge2 - rge1 + 1)) + rge1 ; tdmg = (v[20]) * dmg ; tdmg

where v[20] depends on states that the character can have

I've been searching a bit in order for the skill to depend on the target's hpRate. As I wanted the skill to not be overpowered below the 10% hp, I tired to make an event changing a variable or a if(b.hpRate()) kind of thing in the damage formula.
The issue comes there, cause when I try the skill it doesn't deal damage anymore. So what I want to achieve is this kind of result :
-if the HP of the target is above 80% of its maximum, the damage of the skill is reduced by 20%
-if the HP of the target is above 50% of its maximum, the damage of the skill is normal
-if the HP of the target is above 20% of its maximum, the damage of the skill is increased by 20%
-if the HP of the target is under 20% of its maximum, the damage of the skill is increased by 50%

Can I achieve it with my current damage formula ? Is there a way to have a 'if x ? else : if y ?' situation in RMMV ?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,363
Reaction score
8,085
First Language
German
Primarily Uses
RMMV
when I try the skill it doesn't deal damage anymore.
if the damage formula works without that extension but not with it, then that is usually a sign that there is either an undefined name or a typo in the formula - because the eval breaks to zero if encountering an error during processing.

you might get some help in finding that error if you post what doesn't work.

That said, I suggest a slightly different approach to prevent that mess of damage formulae.
A damage formula can call any global script function, so I suggest requesting a plugin that does nothing but define some global formulae to be used in the damage function.

then you write the more complex parts of your damage process into that plugin and just call the calculation from the damage formula. This will make your formulae much more readable.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
165
Reaction score
191
First Language
Danish
Primarily Uses
RMMV
Sure, the following should do it. Just replace the last tdmg with it.

Code:
tdmg * (b.hpRate() > 0.8 ? 0.8 : (b.hpRate() > 0.5 ? 1 : (b.hpRate() > 0.2 ? 1.2 : 1.5)))

It is basically a simplified bunch of if-else statements in a single line.
 

Deagron

Veteran
Veteran
Joined
Aug 14, 2020
Messages
42
Reaction score
6
First Language
French
Primarily Uses
RMMV
Sure, the following should do it. Just replace the last tdmg with it.

Code:
tdmg * (b.hpRate() > 0.8 ? 0.8 : (b.hpRate() > 0.5 ? 1 : (b.hpRate() > 0.2 ? 1.2 : 1.5)))

It is basically a simplified bunch of if-else statements in a single line.
It worked ! thank you :)
 

Latest Threads

Latest Profile Posts

Updated the dev logs for the game I'm working on! Check it out here
Alright, I left the modern girl in fantasy brain's hands while I get my - MODERN GIRL WHAT HAPPENED?! I blame fantasy brain for this.

WinaElemental.png
I just realized that, while I was waiting for our little Easter Game to be approved in the Completed Games Thread, the game was already listed for more than a week, without me noticing x.x

So ... very delayed happy easter to everyone I guess? : D
WIP
3t2Xc52pKS7ptwWCFMrSen.png

Forum statistics

Threads
110,561
Messages
1,054,261
Members
143,673
Latest member
hesena
Top