# TUTORIAL: Damage formulas 101

**URL:** <https://guild.rpgmakerofficial.com/t/topic/2961>\
**Category:** 素材\
**Created:** [September 15, 2026, 11:52am UTC](https://guild.rpgmakerofficial.com/t/topic/2961 "2026-09-15T11:52:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skunk](https://sea2.discourse-cdn.com/flex002/user_avatar/guild.rpgmakerofficial.com/skunk/32/7366_2.png) [@Skunk](https://guild.rpgmakerofficial.com/u/Skunk)\
**Post date:** [September 15, 2026, 11:52am UTC](https://guild.rpgmakerofficial.com/t/topic/2961/1 "2026-09-15T11:52:20Z")

</div>

Damage Formulas 101  
A comprehensive guide for RPG Maker MV & MZ

Damage formulas in RPG Maker are plain JavaScript expressions.  
They follow normal math order of operations (PEMDAS):

1. Parentheses
2. Exponents
3. Multiplication & Division (left to right)
4. Addition & Subtraction (left to right)

Because of this, a.atk \* 4 - b.def \* 2 is not the same as (a.atk \* 4 - b.def) \* 2.  
Always use parentheses when you need to control the order.

* * *

The Two Most Important Variables

a = the user (attacker)  
b = the target (defender)

You can access almost any parameter from them:

a.atk, a.def, a.mat, a.mdf, a.agi, a.luk  
a.hp, a.mp, a.tp, a.mhp, a.mmp  
a.level, a.hpRate(), a.mpRate(), a.tpRate()

Same options exist for b.

* * *

Basic Operators

- Addition → a.atk + 50

- Subtraction → a.atk - b.def

- Multiplication → a.atk \* 4  
/ Division → a.atk / 2  
% Modulo → a.hp % 10  
\*\* Exponent → a.atk \*\* 2

* * *

Useful Math Functions

Math.max(x, y) // higher value  
Math.min(x, y) // lower value  
Math.floor(x) // round down  
Math.ceil(x) // round up  
Math.round(x) // normal rounding  
Math.random() // 0 to 1  
Math.randomInt(n) // 0 to n-1

* * *

Essential Formula Building Blocks

1. Classic Physical  
a.atk \* 4 - b.def \* 2

2. Classic Magical  
a.mat \* 4 - b.mdf \* 2

3. Percentage of Max HP  
b.mhp \* 0.25

4. Current / Missing HP  
b.hp \* 0.3  
(b.mhp - b.hp) \* 0.5

5. Level Scaling  
a.atk \* 2 + a.level \* 5

6. Minimum Damage Guarantee  
Math.max(a.atk \* 4 - b.def \* 2, 1)

7. Using Variables  
a.atk \* 4 - b.def \* 2 + v[10]

8. Conditional (ternary)  
a.hpRate() \< 0.3 ? a.atk \* 6 : a.atk \* 4

9. Element Rate  
(a.atk \* 4 - b.def \* 2) \* b.elementRate(2)

* * *

Practical Full Examples

Balanced Physical Skill  
Math.max(a.atk \* 4 - b.def \* 2, a.atk)

Magic with Level Scaling  
a.mat \* 3 + a.level \* 8 - b.mdf \* 1.5

True Damage (ignores defense)  
a.atk \* 3

Execute (stronger under 25% HP)  
b.hpRate() \< 0.25 ? a.atk \* 8 : a.atk \* 3

* * *

Important Notes & Common Pitfalls

- Variance is applied after the formula.
- Critical hits multiply the final result (default ×3) after formula + variance.
- Guard halves damage after everything else.
- Division by zero will crash the game. Always protect it:  
a.atk / Math.max(b.def, 1)
- Very large numbers can cause issues. Prefer keeping values reasonable or using Math.floor().

* * *

Quick Reference Cheat Sheet

a.atk \* 4 - b.def \* 2 // Basic physical  
a.mat \* 4 - b.mdf \* 2 // Basic magical  
Math.max(a.atk \* 4 - b.def \* 2, 1) // Minimum 1 damage  
b.mhp \* 0.2 // 20% max HP  
a.level \* 10 + a.atk \* 2 // Level scaling  
a.hpRate() \< 0.5 ? a.atk \* 5 : a.atk \* 3 // Conditional

* * *

Feel free to ask questions or share your own formulas below.  
Happy formula crafting!
