RMMV Damage Formula - ideas and help

● ARCHIVED · READ-ONLY
Started by Shaz 1539 posts Page 74 of 77 View original ↗
  1. ShatteredRift said:
    I want Weapons and Armor to then apply separately and be much more impactful.
    Okay, then you can just reference the weapon's ATK by itself.
    Code:
    a.weapons()[0].params[2]
    is the primary weapon's ATK value.

    If there's a possibility of your actors being unarmed, put a check in there for it:
    Code:
    (a.weapons()[0] ? a.weapons()[0].params[2] : 0)
  2. ShatteredRift said:
    This would probably be perfect! Since it's a percentage, I can just multiply by 100 to have a range up to 999. And since I hope to handle both Weapons and Armor this way, it should work out perfectly. Thank you!
    For anyone following along, RPGM MV assumes the percentage will be 100% by default, so I had to do (100 * a.elementRate(2) - 100) to make it work. Relevant because I'm also including a disarming mechanic by sealing a character's weapon for the battle... although the fact that enemies can't equip weapons probably means I'll be modifying this later anyway. But at least it works on the player characters.\

    ATT_Turan said:
    Okay, then you can just reference the weapon's ATK by itself.
    Code:
    a.weapons()[0].params[2]
    is the primary weapon's ATK value.

    If there's a possibility of your actors being unarmed, put a check in there for it:
    Code:
    (a.weapons()[0] ? a.weapons()[0].params[2] : 0)
    Thank you! The one issue with this is that I don't want weapons also adding to ATK. Which is easily solved in formula by subtracting the weapon's ATK from the character's ATK. But would still display the combined ATK on the menu. (Haven't even looked at those while I'm learning.)
  3. Hello, I'm trying to set up a damage formula for my project and having trouble (0 experience with this sort of thing).

    What I'm trying to do is have attack - defense and magic attack - magic defence calculated seperately within the same attack, for example, if the target has 1000 defense and 700 m.defense, and I attack with a weapon that has 500 atk, and 1000 m.atk, I'd want it to deal 300 damage.

    The closest I've got trying to come up with it myself was :
    (a.atk - b.def) + (a.mat - b.mdf) * 1
    but this ended up, as far as I can tell, getting -500 from the first set of brackets, which... doesn't really work well.

    I'm sure there's probably a stupidly easy answer here that I'm missing. :kaosigh:
  4. PhantomRaptorDS said:
    Hello, I'm trying to set up a damage formula for my project and having trouble (0 experience with this sort of thing).

    What I'm trying to do is have attack - defense and magic attack - magic defence calculated seperately within the same attack, for example, if the target has 1000 defense and 700 m.defense, and I attack with a weapon that has 500 atk, and 1000 m.atk, I'd want it to deal 300 damage.

    The closest I've got trying to come up with it myself was :
    (a.atk - b.def) + (a.mat - b.mdf) * 1
    but this ended up, as far as I can tell, getting -500 from the first set of brackets, which... doesn't really work well.

    I'm sure there's probably a stupidly easy answer here that I'm missing. :kaosigh:
    So, if you want Atk, Mat, Def, and MDf to all contribute to the same formula, the results of the individual brackets aren't actually going to matter if the numbers don't change. You could easily do (Atk+Mat) - (Def+Mdf) and still get the same result, assuming that the numbers being added and subtracted are always the same.

    From what I understand based on the example you gave though, it sounds like you want to pull the highest number out from the two possible damage calculations, considering the Mat-Mdf example only used the result of 1000 Mat vs. 700 Mdf divorced from the physical stats. This is fortunately very easy!

    If that's what you're going for, you'll want to use Math.max. Specifically for your example:

    Math.max(a.atk - b.def, a.mat - b.mdf);

    What this formula will do is select which item in the array (separated by commas) will yield the highest result, and select that number. So, if your Atk is lower than the target's Def and would deal no damage, but your Mat is higher than the target's Mdf, only the magic stats will apply in this calculation.

    If for whatever reason that's not what you're going for, I think you might need to be a bit more specific, since I can't think of any way to add 500+1000 minus 1000+700 and pull any positive number.
  5. Maybe something like this will be do the trick

    Math.max(0, a.atk-b.def)+Math.max(0,a.mat-b.mdf)

    In this case, if the def is greater than the atk like in your example, this part will be equal to zero and will not impact the magic part.
  6. Thank you both for your replies! Sorry about wording all of that pretty terribly, what I should have focused on was that I didn't want the result to be able to go into negative numbers. Boonty's suggestion seems to work perfectly for what I was looking to do! Tysm :kaojoy:
  7. PhantomRaptorDS said:
    Thank you both for your replies! Sorry about wording all of that pretty terribly, what I should have focused on was that I didn't want the result to be able to go into negative numbers. Boonty's suggestion seems to work perfectly for what I was looking to do! Tysm :kaojoy:
    Normally, when the result is a negative, it should not do any damage. However, if you want to make sure the minimum is 0, or any other number, you can use:
    Code:
    Math.max(0, X)

    Replace X with your own formula. Now, the outcome is either 0 or the outcome of your formula. Whichever is the highest value.

    Replace 0 with whatever you want the minimum to be.

    Edit:
    Oh never mind. I see that was already said. Oops.
  8. Trying to make a skill that Drains a percentage of the target's current TP and grants it to the user. Idk whereto even start as the one thing I found didn't have any explanations

    I intend to have it be able to be used on any target, including allies if possible, if that matters.
  9. Zakarijah said:
    Trying to make a skill that Drains a percentage of the target's current TP and grants it to the user. Idk whereto even start as the one thing I found didn't have any explanations
    Everything you need is explained in this thread:
    Damage Formulas 101
    Note that it is best practice to not do this in a damage formula, but to use a plugin like Yanfly's Skill Core.
  10. ATT_Turan said:
    Everything you need is explained in this thread:
    Damage Formulas 101
    Note that it is best practice to not do this in a damage formula, but to use a plugin like Yanfly's Skill Core.
    There has to be a simpler way to do this without a plugin. It's a single skill for one of my characters and no one else, including enemies.
  11. Zakarijah said:
    There has to be a simpler way to do this without a plugin. It's a single skill for one of my characters and no one else, including enemies.
    ...then you use the information in the thread I already linked to you?

    I was telling you, because that thread doesn't say it, that if you put skills on enemies or use the Auto Battle trait, JavaScript functions in the damage formula will produce unexpected results. I'm not sure what your question or confusion is. Please clarify.
  12. I'm not sure how to do a %, but you can do something like this:

    a.gainTp(45); b.gainTp(-45);
  13. Maldra said:
    I'm not sure how to do a %
    To get a portion of a number you can either divide it by another number (fractions) or multiply by a decimal.

    100/2
    100*.5
    will both give you 50% of 100.

    For what it's worth, the above poster got their question figured out in another thread using some plugin notetags.
  14. Well, what I meant is I wasn't sure how to do a % of their current TP. The code I provided him simply subtracts tp and adds tp to the user without checking the target's actual TP.
  15. Maldra said:
    Well, what I meant is I wasn't sure how to do a % of their current TP.
    The same math applies.
    b.tp/2
    b.tp*.5
    both give you 50% of the target's TP.

    The b.tp part of it is in the tooltip for the damage formula box.

    When dividing, you do want to use a JavaScript function to make sure you don't accidentally work with decimals. So, for example, Math.round(b.tp*.5)
  16. Hello! So I'm using Yanfly's Selection Control plugin and while it has a disperse damage/healing option, said option splits it evenly among all targets. However, I'd like for it to instead work like it typically does in Final Fantasy games where selecting multiple targets just causes the damage to be cut in half or so. So like a spell does ~1,000 damage on one target, but it's ~500 to each target if it's two or more.

    While I'm familiar with being able to spread damage evenly across targets or apply a state to the user in the formula, how would I go about doing this act of wizardry? Sorry if this is necroposting, and thank you in advance!
  17. TailsFiraga said:
    Hello! So I'm using Yanfly's Selection Control plugin and while it has a disperse damage/healing option, said option splits it evenly among all targets. However, I'd like for it to instead work like it typically does in Final Fantasy games where selecting multiple targets just causes the damage to be cut in half or so.
    So you would not use the Disperse Damage tag on the skill. Instead, give it the Yanfly Skill Core notetag:
    Code:
    <Pre-Damage Eval>
    if (BattleManager._targets.length>1)
        value/=2;
    </Pre-Damage Eval>

    I think that should work with each target getting passed the original damage value. If instead you see each target taking half successively, we can do something more complex.
  18. ATT_Turan said:
    So you would not use the Disperse Damage tag on the skill. Instead, give it the Yanfly Skill Core notetag:
    Code:
    <Pre-Damage Eval>
    if (BattleManager._targets.length>1)
        value/=2;
    </Pre-Damage Eval>

    I think that should work with each target getting passed the original damage value. If instead you see each target taking half successively, we can do something more complex.

    Thank you for the speedy reply! Upon applying this to a few spells to test it out, it works with one spell but for some reason doesn't seem to work with two other spells that are otherwise the same, which I assume is just RPG Maker being lovely and quirky but I am frantically checking to make sure I copied things correctly just in case. It also doesn't seem to work with the healing spells, probably because they don't do "damage."

    As a side thing, and it's probably just RPG Maker MV itself being a little silly, but sometimes it just adds the number "5" to the end of the damage numbers. It doesn't affect the damage at all, the game just really likes to display the number 5.

    haha silly numbers
    Placeholdery placeholder stuff for sure
    1696209131244.png
  19. TailsFiraga said:
    As a side thing, and it's probably just RPG Maker MV itself being a little silly, but sometimes it just adds the number "5" to the end of the damage numbers. It doesn't affect the damage at all, the game just really likes to display the number 5.
    the 5 is the engine not rounding. youll have to use Math.ceil() or some other rounding function to get rid of decimal results
    try replacing that value/=2 line with
    Code:
    value = Math.ceil(value/2);

    also pre-damage tags should work on healing skills. try sharing a pic of the skills that arent working as they are in the database?

    EDIT: just thought of it. do your healing skills use the formula box, or did you use a recover hp effect?
  20. @TailsFiraga As @Robro33 said, you need to round the damage: you can use Math.ceil(), Math.floor(), or Math.round()

    And yes, healing is also processed as damage.

    I'd suggest you start a new thread if they still don't work correctly, as this doesn't have anything to do with the damage formula.

    Post screenshots of the skills there, but first double check the order of all Yanfly plugins against the list on the Yanfly Engine Web site. Anything out of order can cause random bugs.