# Damage Formulas 101

#### Eden019

##### Veteran I would like to make a skill that deals additional damage based on the difference between the actor's ATK multiplier and the enemy's ATK multiplier.

Theoretically saying :
a.atk * 4 - b.def * 2 + (a.atk - b.atk)

is this correct ?

#### ATT_Turan

##### Forewarner of the Black Wind I would like to make a skill that deals additional damage based on the difference between the actor's ATK multiplier and the enemy's ATK multiplier.

Theoretically saying :
a.atk * 4 - b.def * 2 + (a.atk - b.atk)

is this correct ?
Maybe? The syntax is correct, that formula will function in RPG Maker.

Whether it does what you want is kind of up to you. You say you want "the difference between the actor's ATK multipler and the enemy's ATK multiplier," but there's no such thing in the engine and you're not multiplying them by anything in your formula (well, you're multiplying the actor's ATK at the beginning).

The last bit of your formula is just adding (or subtracting) the difference between their ATK parameters. Is that what you mean?

If you don't think your formula is doing what you want, try to reword what your goal is.

#### ThreeSixNine

##### Veteran @crackkillz There's another way to reference the attack value of an equipped weapon:
user.equips().params
Would return the attack stat (param 2) of the first equip slot (equips()).

You can reference an actors base strength stat, before any bonuses from gear of buffs with:
user.paramBase(2)

Conversely, you can reference ONLY the bonus values of a parameter using:
user.paramPlus(ID)
Where "ID" is the number of the param you want to check.

• crackkillz

#### Eden019

##### Veteran Maybe? The syntax is correct, that formula will function in RPG Maker.

Whether it does what you want is kind of up to you. You say you want "the difference between the actor's ATK multipler and the enemy's ATK multiplier," but there's no such thing in the engine and you're not multiplying them by anything in your formula (well, you're multiplying the actor's ATK at the beginning).

The last bit of your formula is just adding (or subtracting) the difference between their ATK parameters. Is that what you mean?

If you don't think your formula is doing what you want, try to reword what your goal is.
it actually works. But, I forgot to explain about the multiplier... i will explain it

Bonus damage is based on the difference between A.atk and B.atk, but it will be multiplied based on the difference , so the higher the difference --- the higher bonus damage.

Notes and example :
- Actor A ATK is 50, meanwhile Actor B ATK is 20
the difference is : 50-20 = 30 points.

- difference multiplier :
0 - 30 points : x1 bonus (bonus 0-30 damage)
31 - 50 points : x3 bonus (bonus 93-150 damage)
50 - 99 points : x5 bonus (bonus 250- 495 damage)
> 99 points : x10 bonus (bonus 990+ damage)

- if B.atk is higher than A.atk , no bonus damage. it will just do normal damage.

#### ATT_Turan

##### Forewarner of the Black Wind - difference multiplier :
0 - 30 points : x1 bonus (bonus 0-30 damage)
31 - 50 points : x3 bonus (bonus 93-150 damage)
50 - 99 points : x5 bonus (bonus 250- 495 damage)
> 99 points : x10 bonus (bonus 990+ damage)

- if B.atk is higher than A.atk , no bonus damage. it will just do normal damage.
Erm...okay? None of that is in the formula you posted, so we can't tell you if you did it correctly.

But if you're confident you have that part and you wanted to check that how you're fitting it into the rest of the formula is mathematically correct, then yes.

#### UmbrotheUmbreon

##### Legendary Umbreon So I don't know where I'm going wrong with this code, but it's sort of working as intended with a minor hiccup. I think I know what the hiccup is, but would like some clarification on it.
Code:
``v = (v||0) + 1; if (v >= 10) {(100 + a.mat + v) * 2 - b.mdf * 2; a.addBuff(4, 2); b.mdf*10} else {(100 + a.mat + v) * 2 - b.mdf * 2}``

So the way the spell is supposed to work is when using it, the Fire variable (which is 3) should increase by one. If the variable is less than 10 it should do the normal formula damage of (100 + a.mat + v) * 2 - b.mdf * 2

That works perfectly fine. However, once the variable hits 10 or more, it should do the same damage but add a buff to the player. Before I didn't have the b.mdf*10 and the spell wouldn't do any damage and just applied the buff. I added it, and when the variable hits 10, all damage from that spell now does a flat 100 (I continued using the spell 4 times in playtesting and all 4 did 100 damage). I think the issue revolves around the b.mdf*10 but without it the spell only applies the buff and doesn't do any damage.

#### ATT_Turan

##### Forewarner of the Black Wind So I don't know where I'm going wrong with this code, but it's sort of working as intended with a minor hiccup. I think I know what the hiccup is, but would like some clarification on it.
Code:
``v = (v||0) + 1; if (v >= 10) {(100 + a.mat + v) * 2 - b.mdf * 2; a.addBuff(4, 2); b.mdf*10} else {(100 + a.mat + v) * 2 - b.mdf * 2}``
The problem is in your if. Expanding it onto separate lines:
```if (v >= 10) {(100 + a.mat + v) * 2 - b.mdf * 2;``` <- Right here, this isn't doing anything. It's just an equation floating in space. You're not setting a variable to the result of this equation, and it's not the last number to be used as the damage result

```a.addBuff(4, 2); b.mdf*10}``` So you're adding the buff and returning magic defense * 10 as the damage

Per the instructions in the first post of this thread, whatever you want to do as your damage has to be the last number in the formula. So delete that mdf*10 thing and swap the order of addBuff and the other equation so the equation is last.

• UmbrotheUmbreon

#### UmbrotheUmbreon

##### Legendary Umbreon The problem is in your if. Expanding it onto separate lines:
```if (v >= 10) {(100 + a.mat + v) * 2 - b.mdf * 2;``` <- Right here, this isn't doing anything. It's just an equation floating in space. You're not setting a variable to the result of this equation, and it's not the last number to be used as the damage result

```a.addBuff(4, 2); b.mdf*10}``` So you're adding the buff and returning magic defense * 10 as the damage

Per the instructions in the first post of this thread, whatever you want to do as your damage has to be the last number in the formula. So delete that mdf*10 thing and swap the order of addBuff and the other equation so the equation is last.
Oh my god dude thank you so much! It turns out the problem was the damage not being in the last part of the first formula. Once I put the a.addBuff(4, 2); code before the damage part it began to work properly!

#### UmbrotheUmbreon

##### Legendary Umbreon Now I have an entirely new issue. I was trying to expand the code to make it so if the enemy has an elemental weakness, the variable increases by 2 instead of 1. This piece of gimmick is to encourage players to utilize elements that are strong against foes to quickly build alignment. This current code I'm using works perfectly as intended
Code:
``v = (v||0) + 1; if (v >= 10) {a.addBuff(4, 2); (100 + a.mat + v) * 2 - b.mdf * 2} else {(100 + a.mat + v) * 2 - b.mdf * 2}``

So I thought I needed to add an if statement checking the b.elementRate(2) as 2 is the for Fire that I'm testing this code with. I used this code and it does no damage and doesn't increase the variable. I have the element rate set to 150% on the enemy I'm testing.

Code:
``v = (v||0) b.elementRate(2) > 0 ? + 2 : + 1; if (v >= 10) {a.addBuff(4, 2); (100 + a.mat + v) * 2 - b.mdf * 2} else {(100 + a.mat + v) * 2 - b.mdf * 2}``

I really do apologize with how often I come here for help....and sometimes I really do feel like it's for dumb things, but I get lost easily sometimes and tend to need help with what I'm doing.

#### ATT_Turan

##### Forewarner of the Black Wind So I thought I needed to add an if statement checking the b.elementRate(2) as 2 is the for Fire that I'm testing this code with. I used this code and it does no damage and doesn't increase the variable.
So split it up like we did before.
Code:
``v = (v||0) b.elementRate(2) > 0 ? + 2 : + 1;``
This is invalid syntax. The ternary operator can only contain a right or left side operand, it can't contain the actual operator. The way this reads is two separate statements:
```v=v || 0 b.elementRate ... etc ``` <- This just produces a floating "+2" or "+1" that doesn't mean anything

It should work fine if you put the operator in the correct place and separate it from the previous operator with parentheses.
Code:
``v = (v||0) + (b.elementRate(2) > 0 ? 2 : 1);``

Incidentally, you know that elementRate > 0 is true by default? That number is what damage gets multiplied by, so all actors and enemies start with an elementRate for every element of 1. Greater than 1 will indicate they're vulnerable to that element, less than 1 is a resistance.

Last edited:

#### UmbrotheUmbreon

##### Legendary Umbreon So split it up like we did before.

This is invalid syntax. The ternary operator can only contain a right side operand, it can't contain the actual operator. The way this reads is two separate statements:
```v=v || 0 b.elementRate ... etc ``` <- This just produces a floating "+2" or "+1" that doesn't mean anything

It should work fine if you put the operator in the correct place and separate it from the previous operator with parentheses.
Code:
``v = (v||0) + (b.elementRate(2) > 0 ? 2 : 1);``

Ah okay. I didn't realize that. So anytime I wanna use do something to a variable in the formula, but have conditions set with it, I should be using + to connect the variable to the condition right?

Incidentally, you know that elementRate > 0 is true by default? That number is what damage gets multiplied by, so all actors and enemies start with an elementRate for every element of 1. Greater than 1 will indicate they're vulnerable to that element, less than 1 is a resistance.

This I was aware of, but I wanted to test the code to make sure the variable increase was actually for 2 and not just 1 first. If it didn't increase it by 2, then I would know I did something wrong in the formula as it should automatically read as a true statement.

#### ATT_Turan

##### Forewarner of the Black Wind Ah okay. I didn't realize that. So anytime I wanna use do something to a variable in the formula, but have conditions set with it, I should be using + to connect the variable to the condition right?
Erm...sure?

All operators in JavaScript (just like in the math you're used to) have the format `value operator value`
e.g. 2 + 2

All of those things produce a value which you could then use on one side of another operator if you so wished. e.g. `(2 + 2) * 4`

The ternary operator isn't different except, per its name, it uses 3 things to create its end value instead of 2. It still produces and functions as a value - you wouldn't try to say, in the example above, `(/ + 2) * 4` - that clearly doesn't mean anything.

#### UmbrotheUmbreon

##### Legendary Umbreon Ah alright. Thank you again for the help, I really hate being a bother and it really does seem like obvious things once they are pointed out. Hopefully one day I can reliably do this without constantly pondering the forum

### Latest Profile Posts Making a "characters first appearance" drawing for my game. Now I just have to finish the sprite art animation for her grand entrance.​
A secret desire of mine: I want to make a horror game based on Celtic mythology. I've seen plenty of Greek, Japanese and Norse mythology-based horror games, but I don't think I've ever seen a Celtic-based horror game anywhere...
FF Opera Omnia is in quite a bizarre state right now. As soon as the tutorial is completed, the game levels all characters to level 70 and makes all new characters start at level 70.