# RMMV Damage Formula - ideas and help

#### Gargoyle77

##### Veteran
Hello, everyone. I tried reading the damage formula 101, but can't make what I have in mind work. Basically I want the formula to check if the target is affected by certain state. If so, then that state is removed, then the user vaina some mp and finally certain amount of dmg is applied. And if the target is not affected by that state, then normal dmg is applied. How can accomplish this? Thanks for reading !

#### Arctica

##### Veteran
Hello, everyone. I tried reading the damage formula 101, but can't make what I have in mind work. Basically I want the formula to check if the target is affected by certain state. If so, then that state is removed, then the user vaina some mp and finally certain amount of dmg is applied. And if the target is not affected by that state, then normal dmg is applied. How can accomplish this? Thanks for reading !

Hmm let's say.. your initial damage (for the skill in question) is 20

Code:
``````if (b.isStateAffected(stateId) === false) {
20;
} else {
b.removeState(stateId);
a.gainMp(amount);
20 * someMultiplierOfYourChoice;
};``````

Am I on the right track here?
Edit: corrected var misshap.

Last edited:

#### Gargoyle77

##### Veteran
Hmm let's say.. your initial damage (for the skill in question) is 20

Code:
``````if (b.isStateAffected(stateId) === false) {
20;
} else {
b.removeState(stateId);
a.gainMp(amount);
20 * someMultiplierOfYourChoice;
};``````

Am I on the right track here?
Edit: corrected var misshap.
Worked perfectly fine. Thanks a lot for your help

#### cubeking1

##### Villager
ive been trying to make a skill that ramps its damage up with each use but the first use the skill is always zero what am i missing?

((a.atk+(a.luk/2))*(.8+(v[21]*.2)))*4-(b.def+(b.luk/2))*2

#### Zealvern

##### Villager
I'm doing a thing, in a nutshell I want my healer to have an attack that hits an enemy and restores the most wounded ally's HP based on half the damage dealt, but it gives 0. Please be noted I have zero idea of JavaScript

var damage=a.atk-b.def; var group=\$gameParty.aliveMembers(); group[group.reduce(((lowest, next, index) => group[next].hp < group[lowest].hp : index ? lowest), 0)].gainHp(damage/2); damage

I was given this code on other post. Can this script be fixed or is there a better way to do it?

Last edited:

#### Solar_Flare

##### Veteran
You seem to be overcomplicating your code; there's no need to care about the index of the most wounded member. I tried simplifying it and came up with this; let me know if it works. (Of course you need to remove the line breaks to use it in the damage box.)

JavaScript:
``````var damage=a.atk-b.def;
var group=\$gameParty.aliveMembers();
var mostWounded = group.reduce((lowest, next) => next.hp < lowest.hp : next ? lowest)
mostWounded.gainHp(damage/2);
damage``````

Or with fewer variables:

JavaScript:
``````var damage=a.atk-b.def;
\$gameParty.aliveMembers().reduce((lowest, next) => next.hp < lowest.hp : next ? lowest).gainHp(damage/2);
damage``````

(As to whether there's a better way to do it… probably, but it would require a plugin.)

#### Zealvern

##### Villager
You seem to be overcomplicating your code; there's no need to care about the index of the most wounded member. I tried simplifying it and came up with this; let me know if it works. (Of course you need to remove the line breaks to use it in the damage box.)

JavaScript:
``````var damage=a.atk-b.def;
var group=\$gameParty.aliveMembers();
var mostWounded = group.reduce((lowest, next) => next.hp < lowest.hp : next ? lowest)
mostWounded.gainHp(damage/2);
damage``````

Or with fewer variables:

JavaScript:
``````var damage=a.atk-b.def;
\$gameParty.aliveMembers().reduce((lowest, next) => next.hp < lowest.hp : next ? lowest).gainHp(damage/2);
damage``````

(As to whether there's a better way to do it… probably, but it would require a plugin.)
Negative, it does zero. For your information, if it would require a plugin, I have the whole YEP pack

#### Solar_Flare

##### Veteran
Well, the way to debug what's wrong with the formula would be to past the key part into the developer console (which can be opened with either F8 or F12) and press enter:

JavaScript:
``\$gameParty.aliveMembers().reduce((lowest, next) => next.hp < lowest.hp : next ? lowest)``

At a glance, I think the ? and : need to switch places.

#### ATT_Turan

##### Forewarner of the Black Wind
@Zealvern it doesn't make much sense to post the same questions in a different thread while you have your own thread active. The only thing it can accomplish is confusing two conversations - in this case, Solar_Flare was posting trying to help you hours after I already gave you working code in your original thread.

@Solar_Flare the over-complication was my fault for not being sufficiently well-versed in how reduce works (and yes, my original post to him did copy a snippet from a blog post that had the ternary operators reversed, it took me two posts to notice).

#### Zealvern

##### Villager
@Zealvern it doesn't make much sense to post the same questions in a different thread while you have your own thread active. The only thing it can accomplish is confusing two conversations - in this case, Solar_Flare was posting trying to help you hours after I already gave you working code in your original thread.

@Solar_Flare the over-complication was my fault for not being sufficiently well-versed in how reduce works (and yes, my original post to him did copy a snippet from a blog post that had the ternary operators reversed, it took me two posts to notice).
Yeah, you're right, sorry, wanted to cover a wider area in order to get the biggest amount of possible solutions and get the drill on how do more complex formulas work, that's all on me.

#### pokestar

##### Warper
I'm trying to create a skill that does x2 damage if the foe is inflicted with poison, much like the move venoshock from Pokémon. Could anyone please help me?

#### ATT_Turan

##### Forewarner of the Black Wind
I'm trying to create a skill that does x2 damage if the foe is inflicted with poison, much like the move venoshock from Pokémon. Could anyone please help me?
There are examples of how to implement this ins the Damage Formula 101 thread.
But you would do:
`(yourDamageFormula)*(b.isStateAffected(X) ? 2 : 1)`
where X is the ID of the poison state.

#### pokestar

##### Warper
There are examples of how to implement this ins the Damage Formula 101 thread.
But you would do:
`(yourDamageFormula)*(b.isStateAffected(X) ? 2 : 1)`
where X is the ID of the poison state.
thanks

#### Vis_Mage

##### Wisp Charmer
Is there a way I can have a skill that has a percentage change to apply multiple of a debuff to the target? (I'm using debuffs instead of a state because they can stack)

For example, a skill that does damage, but also has a 50% chance to apply 5 ATK debuffs with a duration of 3 turns.

#### ATT_Turan

##### Forewarner of the Black Wind
Is there a way I can have a skill that has a percentage change to apply multiple of a debuff to the target? (I'm using debuffs instead of a state because they can stack)

For example, a skill that does damage, but also has a 50% chance to apply 5 ATK debuffs with a duration of 3 turns.
Code:
``if (Math.random()<0.5) {b.addDebuff(2, 3); b.addDebuff(2, 3); b.addDebuff(2, 3); b.addDebuff(2, 3); b.addDebuff(2, 3);};``

#### Vis_Mage

##### Wisp Charmer
Code:
``if (Math.random()<0.5) {b.addDebuff(2, 3); b.addDebuff(2, 3); b.addDebuff(2, 3); b.addDebuff(2, 3); b.addDebuff(2, 3);};``
Works like a charm, thank you very much!

#### Bumbini

##### Warper
I'm playing around with non-standard damage, thinking about using TP as balance or momentum, where you need to accumulate a high TP ratio to do significant damage. The problem is the TP gain/loss on attack via the damage formula isn't working and I'm not sure why. My simplified test formula is below. I thought a.tp += x would be way to increment, but it's not doing anything. Am I missing something? Is it possible to increment TP like this?

Would it be smarter to use MP? If I do anything with this, I probably wouldn't be using MP for anything else.

dmg = 5; a.tp += 10; b.tp -= 10; dmg;

edit: Doing a.setTp(a.tp + whatever) worked. Still wondering why += didn't work for that.

Last edited:

#### Vis_Mage

##### Wisp Charmer
I'm trying to set up a skill that does double damage when the user is below 25% HP. I've got this as my damage formula at the moment, but it deals 0 damage, and I can't seem to figure out where I have an error:

a.hp =< (a.mhp / 4) ? 2 * (((a.atk * (20 + a.luk)) / b.def)) : ((a.atk * (20 + a.luk)) / b.def);

#### Frostorm

##### []D[][]V[][]D
I'm trying to set up a skill that does double damage when the user is below 25% HP. I've got this as my damage formula at the moment, but it deals 0 damage, and I can't seem to figure out where I have an error:

a.hp =< (a.mhp / 4) ? 2 * (((a.atk * (20 + a.luk)) / b.def)) : ((a.atk * (20 + a.luk)) / b.def);
Shouldn't it be "<=" instead of "=<"?

#### Vis_Mage

##### Wisp Charmer
Shouldn't it be "<=" instead of "=<"?
Oh, haha, that'll do it. It's always the simplest things

Thank you !

### Latest Profile Posts

I had to wrote for my job so called document "Annual Rate", based on this document employees will recieve pay raise. I wrote whole truth how I feel about my work and this is how I would summary my document:
Gonna take a break from helping people with resource requests, it has been too much of a disappointment lately.
whats the easiest way to add an on-map command in RPG Maker? like when you press a button the character just jumps or runs when its held? should i get an ABS plugin and customize?
Thinking of doing a crowdfunding kind of thing on my ko-fi page, but i don't have an audience and i don't want to go to the big crowdfinding sites cause i can't guarantee that i'll complete the project. It's just for fun but i still need some more tools. Anyone else in the same boat?
Pretty proud of this train station i'm making!