设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 86|回复: 0

[交流讨论] A Guide to Damage Formulas

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    前天 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4446

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    22899
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28239

    灌水之王

    发表于 前天 17:34 | 显示全部楼层 |阅读模式
    Additional tutorial credits: @TheoAllen, for converting MV/Z formulas to Ace. The parallels are now included in the intro post.

    If you're uncomfortable going much further than a.atk * 4 - b.def * 2 for your damage formulas, this is the guide for you. Damage formulas are extremely powerful tools that can let you create complex abilities. They are fairly similar to actual scripts in syntax (which is why they can be intimidating).

    I placed this tutorial in Non-Maker Specific because it has worked with MV and VX Ace.

    Basic Setup
    [MV]



    [VX Ace]




    • Type. There are six different damage types: HP damage, MP damage, HP recover, MP recover, HP drain, and MP drain. They each should be fairly self-explanatory. Drain restores health to the user equal to damage dealt (not half as in some games).
    • Element. Element allows you to select the damage element. Normal Attack is best for most physical moves (e.g., a skill like Wild Blow). Elements are important to set for most games because they can let you add in elemental weakness and effectiveness.
    • Variance. Variance is a percentage that lets you set how much the damage will vary from what the formula says. If the formula computes to 50, and if variance is 20%, it can do 80-120% of 50 damage, so 40-60 damage. I recommend setting it to 10%.
    • Critical. Critical allows you to select if the attack can have a critical. Most spells do not have this enabled, in most games. But do what you like!
    Basic Formulas and Parameters

    Onto the meat of the tutorial!

    Before we begin, note the importance of capitalization. Everything must be capitalized as directed in this thread. Do not randomly capitalize or un-capitalize as you desire. If you do, the formulas will not work.

    Let's break down the standard attack formula:
                    Code:        
    1. a.atk * 4 - b.def * 2
    复制代码


    • "a" symbolizes the user, and "b" symbolizes the targets.
    • Think of the period as an apostrophe + s: 's.
    • In other words, "The damage dealt is a's attack multiplied by 4, minus b's defense multiplied by 2." Pretty simple.

      • Say the user's attack is 20, and the enemy's defense is 15. In that case the damage dealt is 20*4-15*2=80-30=50. With a variance of 20, the actual damage will be between 40-60 damage.

    It would now be instructive to look at a standard spell: perhaps Water.
                    Code:        
    1. 300 + a.mat * 2 - b.mdf * 2
    复制代码


      1. mat
      复制代码
      is "magic attack", and
      1. mdf
      复制代码
      is "magic defense".
    • We can interpret the formula this way, "The damage dealt is 300 plus the user's magic attack multiplied by 2, minus the target's magic defense multiplied by 2."

      • Say the user's MAT is 20, and the enemy's MDF is 15. In that case the damage dealt is 300+(20*2-15*2)=300+(40-30)=300+10=310. With a variance of 20, the actual damage will be between 248-372 damage.

    Aura Blade is up next. This skill is slightly more complex:
                    Code:        
    1. a.atk * 4 + a.mat * 3 - b.def - b.mdf
    复制代码


    • The skill description tells us, "Damage is based off user's ATK and MAT."
    • Translating into English, "The damage dealt equals the user's physical attack multiplied by 4 plus the user's magic attack multiplied by 3, minus the target's physical defense and magic defense."

      • Say the user's ATK is 25, MAT is 20, and the enemy's DEF is 30, MDF is 15. In that case the damage dealt is (25*4)+(20*3)-(30)-(15)=100+60-30-15=115. With a variance of 20, the actual damage will be between 92-138 damage. That's not very much - this skill is not necessarily good on all enemies.

    "Okay, but what are all the parameters for a and b, besides atk, def, mat, and mdf?" Turns out that there are quite a lot of them. You will see that some have an ID number listed. This is important for using buffs in a formula, which I will get to towards the end.



      1. level
      复制代码
      - current level, for actor only
      1. hp
      复制代码
      - current HP, NOT max HP
      1. mp
      复制代码
      - current MP, NOT max MP
      1. tp
      复制代码
      - current TP



      1. mhp
      复制代码
      - max HP

      • ID: 0

      1. mmp
      复制代码
      - max MP

      • ID: 1

      1. atk
      复制代码
      - attack stat

      • ID: 2

      1. def
      复制代码
      - defense stat

      • ID: 3

      1. mat
      复制代码
      - magic attack stat

      • ID: 4

      1. mdf
      复制代码
      - magic defense stat

      • ID: 5

      1. agi
      复制代码
      - agility stat

      • ID: 6

      1. luk
      复制代码
      - luck stat

      • ID: 7


    All of the following are decimal numbers. 1.0 converts to 100%. 0.5 converts to 50%. Etc. These values are generally not useful in damage formulas, but are certainly available if you want to get more creative.

      1. hit
      复制代码
      - hit rate
      1. eva
      复制代码
      - evasion rate
      1. cri
      复制代码
      - critical rate
      1. cev
      复制代码
      - critical evasion rate
      1. mev
      复制代码
      - magic evasion rate
      1. mrf
      复制代码
      - magic reflection rate
      1. cnt
      复制代码
      - counter attack rate
      1. hrg
      复制代码
      - HP regeneration rate
      1. mrg
      复制代码
      - MP regeneration rate
      1. trg
      复制代码
      - TP regeneration rate
      1. tgr
      复制代码
      - target rate
      1. grd
      复制代码
      - guard effect rate
      1. rec
      复制代码
      - recovery effect rate
      1. pha
      复制代码
      - pharmacology
      1. mcr
      复制代码
      - MP cost rate
      1. tcr
      复制代码
      - TP charge rate
      1. pdr
      复制代码
      - physical damage rate
      1. mdr
      复制代码
      - magical damage rate
      1. fdr
      复制代码
      - floor damage rate
      1. exr
      复制代码
      - experience rate

    Exercises

    Of course, you don't "have" to do these exercises. However, I find that a good way to learn things like this is to actually try and make your own. If you're up to it, why not try creating...

    • ...a defense-ignoring attack?

    • ...a healing spell dependent on the user's magic attack?

    • ...a resurrection spell that restores half the target's health? How about 5% of it? Or exactly 1 point?

    • ...a sword attack that drains life based on the user's attack and magic attack?

    • ...a simple damage dealing spell (e.g., Fireball)?

    • ...an attack based on the user's attack and defense? How about attack and agility?

    Spoiler: Solutions

      1. a.atk * 4
      复制代码

      1. a.mat * 10
      复制代码
      OR
      1. 250 + a.mat
      复制代码
      OR
      1. b.mhp * 0.25 + a.mat
      复制代码
      , etc.

    • Under Effects, a separate section from the formula, have the effect Remove State [Death] 100%. As for the formula: HP recover, with
      1. b.mhp / 2
      复制代码
      for 50%,
      1. b.mhp / 20
      复制代码
      for 5%, and just
      1. 1
      复制代码
      for 1 health point.

      • See the end of the States section below for a different solution that utilizes only formulas and no effects.

    • Set damage type to HP drain. Formula might look like
      1. a.atk * 4 + a.mat * 4 - b.def - b.mdf
      复制代码
    • Something like
      1. a.mat * 4 - b.mdf * 2
      复制代码
      1. a.atk * 4 + a.def * 2 - b.def * 2
      复制代码
      and
      1. a.atk * 4 + a.agi * 2 - b.def * 2
      复制代码
    None of those exercises included any of the decimal parameters. You generally will not need them.

    Everything included in the default VX Ace skill list has been covered by everything before this point, and more besides. So at this point we are finished with the basics and can proceed to the more complex formula functions!


    Frog Drop: Using Level, Variables, and "If-Else"

    In Final Fantasy 9, a minigame exists whereby the player catches frogs. A character has a skill, called "Frog Drop", that increases in power directly dependent on the number of frogs caught and the level of the character, as follows:
                    Code:        
    1. Damage = Quina's level * Number of frogs caught
    复制代码

    (It is supposed to drop all frogs ever caught onto the target.) This is quite easy to replicate in RM and is instructive for the tutorial, as it will let us examine variables and "if-else". We already learned how to get the character's level:
                    Code:        
    1. a.level
    复制代码

    In RM, the best way to replicate the frogs caught is via a variable. Variables can actually be used in damage formulas, to great effect! Say Variable 1 is "Frogs caught". Then the damage formula would be:
                    Code:        
    1. a.level * v[1]
    复制代码

    Quite simple, really. Now, in FF9, if no frogs are caught, the skill deals 1 damage. But as our formula stands, it would deal 0 damage (if v[1] is 0, then we multiply by 0 and get 0). How can we correct this? With an "if-else" statement, we can check to see if frogs have been caught. If not, 1 damage is dealt. Behold the following:
                    Code:        
    1. v[1] > 0 ? a.level * v[1] : 1
    复制代码

    What does that mean? The syntax is as follows:
                    Code:        
    1. statement ? formula1 : formula2
    复制代码

    Formula1 is used if statement is true. Formula2 is used otherwise. So what we are doing is saying, "Is Variable 1 greater than (>) 0? If so, then we're using the ordinary frog drop formula. Otherwise, Variable 1 must be 0. If it's 0, we'll just do 1 damage."

      1. >
      复制代码
      - greater than
      1. <
      复制代码
      - less than
      1. >=
      复制代码
      - greater than or equal to
      1. <=
      复制代码
      - less than or equal to
      1. ===
      复制代码
      - equal to
      1. &&
      复制代码
      - and
      1. ||
      复制代码
      - or
      1. !==
      复制代码
      - not equal to
      1. !
      复制代码
      - not

    States and Multiple Lines

    By far one of the most powerful and cool things you can do with damage formulas is state checks. Say you have a state, Poison. Maybe an attack deals extra damage if the target is poisoned. In Pokemon, the skill Venoshock does exactly this:
    The user drenches the target in a special poisonous liquid. Its power is doubled if the target is poisoned.
    Click to expand...

    We can replicate this in RPG Maker through an if-else statement, using the ternary operator, ?.
    MV/Z:
                    Code:        
    1. b.isStateAffected(2) ? 2 * (a.atk * 4 - b.def * 2) : a.atk * 4 - b.def * 2
    复制代码

    VX Ace:
                    Code:        
    1. b.state?(2) ? 2 * (a.atk * 4 - b.def * 2) : a.atk * 4 - b.def * 2
    复制代码



    • This formula assumes that Poison is state 2. Change 2 accordingly if necessary.
    • First, we just check to see if the target is poisoned (
      1. b.isStateAffected(2)
      复制代码


      • If the target is poisoned, it deals the normal damage formula, but doubled (
        1. 2 * (a.atk * 4 - b.def * 2)
        复制代码
        ).

      • Otherwise, it just does the normal formula (
        1. a.atk * 4 - b.def * 2
        复制代码
        ).


    Here are the rest of the state formulas. Make sure to place either a. or b. before each one.

    • MV/Z:
      1. isDeathStateAffected()
      复制代码
      - is the target dead? Returns a boolean (true or false)


      • VX Ace:
        1. death_state?()
        复制代码


    • MV/Z:
      1. resetStateCounts(ID)
      复制代码
      - refreshes how long a state will last for the battler. Does not return a value


      • If trying to replicate Venoshock, you could add this line so that the target not only takes extra damage, the poison is also renewed on them.​

      • VX Ace:
        1. reset_state_count
        复制代码


    • MV/Z:
      1. updateStateTurns()
      复制代码
      - shortens all states on battler by 1 turn. Does not return a value


      • VX Ace:
        1. update_state_turns
        复制代码


    • MV/Z:
      1. addState(ID)
      复制代码
      - adds state. Does not return a value


      • VX Ace:
        1. add_state(ID)
        复制代码


    • MV/Z:
      1. isStateAddable(ID)
      复制代码
      - can state be added? Returns a boolean


      • VX Ace:
        1. state_addable?(ID)
        复制代码


    • MV/Z:
      1. removeState(ID)
      复制代码
      - remove state. Does not return a value


      • VX Ace:
        1. remove_state(ID)
        复制代码


      1. states.length
      复制代码
      - checks how many states are on the battler. Returns an integer.


        1. b.states.length * 500
        复制代码
        would deal 500 damage for each state on the target.


    Semicolons are used to separate multiple lines of formula code. Let's revisit our Resurrection spell.
                    Code:        
    1. b.mhp / 2
    复制代码

    We can change this as follows:
    MV/Z:
                    Code:        
    1. b.removeState(1); b.mhp / 2
    复制代码

    VX Ace:
                    Code:        
    1. b.remove_state(1); b.mhp / 2
    复制代码

    Voila! The target's death state is removed and they are healed to 50% HP. Here, we can remove the death heal effect from the Effects section. This will let us combine everything in the damage formula, which I would argue is better.


    Two Important Notes on Extra Lines

    If you have multiple lines of formula, only the last line will actually do damage! So if you have the following:
                    Code:        
    1. a.atk * 4 - b.def * 2; a.mat * 4 - b.mdf * 2
    复制代码

    Only the
    1. a.mat * 4 - b.mdf * 2
    复制代码
    will be computed as damage. So make sure that any prior lines you have are not damage dealing (in the example with the death state removal, that's fine, since no damage is dealt or healed).


    In addition, if you want to write something that does not deal damage in a formula, you must also write another line with a 0 in it. What I mean is, you cannot simply write something like
    1. b.removeState(1)
    复制代码
    and be done. You must also include a 0, like so:
    1. b.removeState(1); 0
    复制代码
    .


    Other Things


    • HP and MP can be directly controlled with the following formulas, replacing x with the appropriate number or formula:

      • MV/Z:
        1. gainHp(x)
        复制代码


        • VX Ace:
          1. hp += x
          复制代码


      • MV/Z:
        1. gainMp(x)
        复制代码


        • VX Ace:
          1. mp += x
          复制代码


      • MV/Z:
        1. gainTp(x)
        复制代码


        • VX Ace:
          1. tp += x
          复制代码


      • MV/Z:
        1. setHp(x)
        复制代码


        • VX Ace:
          1. change_hp(x)
          复制代码


      • MV/Z:
        1. setMp(x)
        复制代码


        • VX Ace:
          1. change_mp(x)
          复制代码


      • MV/Z:
        1. setTp(x)
        复制代码


        • VX Ace:
          1. change_tp(x)
          复制代码


      • MV/Z:
        1. clearTp()
        复制代码


        • VX Ace:
          1. clear_tp
          复制代码



    • To obtain a random number, you can use three different functions:


      • MV/Z:
        1. Math.random()
        复制代码
        - returns a random number between 0 and 1


        • VX Ace:
          1. rand
          复制代码


      • MV/Z:
        1. Math.floor(Math.random()*max)+min
        复制代码
        - returns a random number between min and max

      • MV/Z:
        1. Math.randomInt(max)+min
        复制代码
        - returns a random number between min and max


    • There may come a time when you want a skill to have different effects depending on whether the user/target is an actor or an enemy. In these cases you can use
      1. isActor()
      复制代码
      and
      1. isEnemy()
      复制代码
      (with an a. or b. before each). They return booleans (true-false) and can be used in if-else statements.


      • VX Ace:
        1. is_actor()
        复制代码
        and
        1. is_enemy()
        复制代码


    • Buffs and debuffs can be controlled via formulas. Each stat has a specific parameter ID. I listed those earlier in this guide. Be sure to include a damage line at the end if you use these, even if it is just a 0!

        1. addBuff(ID, turns)
        复制代码


        • VX Ace:
          1. add_buff(ID, turns)
          复制代码


        1. addDebuff(ID, turns)
        复制代码


        • VX Ace:
          1. add_debuff(ID, turns)
          复制代码


        1. removeBuff(ID)
        复制代码


        • VX Ace:
          1. remove_buff(ID, turns)
          复制代码


        1. removeDebuff(ID)
        复制代码


        • VX Ace:
          1. remove_buff(ID, turns)
          复制代码


        1. removeAllBuffs()
        复制代码


        • VX Ace:
          1. clear_buffs
          复制代码



    • You can also use the function
      1. consumeItem($dataItems[ID])
      复制代码
      to make a skill force the target to use an item. A skill might force the target to consume a potion, for example. Be sure to include a damage line.


      • VX Ace:
        1. consume_item(ID)
        复制代码


    Conclusion

    That's all the basics you need to know. For help with specific skills, feel free to ask in this thread. I'll respond when I have time, and other helpful community members probably can too
    . Also, if you see any errors in the the post, please call me out on them so I can correct them.



    本贴来自国际rpgmaker官方论坛作者:lakeisgay处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/a-guide-to-damage-formulas.145148/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-14 14:25 , Processed in 0.098612 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表