RMMV Damage Formula - ideas and help

● ARCHIVED · READ-ONLY
Started by Shaz 1539 posts Page 46 of 77 View original ↗
  1. FenrirDirewolf said:
    Is it possible to add skill mp cost to damage formula? I've tried using many Yanfly plugins commands, but I don't understand much script codes so I've probably messed up somewhere... ^^"

    What I'm trying to do is something like this, where 'X' will be the skill mp cost.

    [ ( X + a.atk*4 + a.tp ) * ( 1 + (a.mp+X)/250 ) * ( 1 - b.def/500 ) ]

    I've found out the command 'a.skillMpCost(X)' returns the MP cost of skill, but I just can't make it work in the damage formula. Does anyone knows how to make it work? Thanks in advance! =D
    what are you using in X? Are you using the skill's id?
    It is not the skill Id that should be there, but the skill itself. Try 'a.skillMpCost($dataSkills[X])'
  2. The code that runs when the engine reads your damage formula is this:
    Code:
    Game_Action.prototype.evalDamageFormula = function(target) {
        try {
            var item = this.item();
            var a = this.subject();
            var b = target;
            var v = $gameVariables._data;
            var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
            var value = Math.max(eval(item.damage.formula), 0) * sign;
            if (isNaN(value)) value = 0;
            return value;
        } catch (e) {
            return 0;
        }
    };

    The "item.damage.formula" is the damage formula that you write in the database. So any variable defined before that can be used.

    Usually you want "a" (the subject, or user of the action), b (the target) and v (the list of game variables). But you also have available "item", which is what the engine calls the skill that's currently being used (because it uses the same structure to refer to skills, equipment and items).

    So you can get the skill's cost with:
    Code:
    item.mpCost

    However, that just returns the skill's base MP cost. To get the cost after modifying it by the actor's MP cost rate SP-parameter, you can write:
    Code:
    a.skillMpCost(item)

    If you're wondering what the engine calls a particular property of a skill - let's say you want to use the skill's TP Cost in the formula, but you don't know what to write to use it in the formula box - there's a quick trick for this. Write this in the formula box:
    Code:
    console.dir(item)

    Then run your game, use the skill and press F8 to open the console window. There will be an "> Object" entry in the log. If you click on it, you see something like this:

    Spoiler
    cPBOxpe.png

    That tells you everything you can use that's inside of the skill. So we can see that the MP cost that I used above is "item.mpCost". Similarly, if you wanted the TP cost, you would write "item.tpCost".

    You can do the same thing to look inside the characters or the game variables. This way you don't have to remember what everything is called - if you forget, you have a way of looking it up.
  3. I need to impose a second damage cap on all of my formulas to prevent them from going beyond 999,999 damage in a single hit. I know the basic idea of what I need, I just don't know how to write it so RMMV will understand it.
    Example:
    If (a.atk * 4) > 999,999, set damage value to 999,999

    How do I write this properly?
  4. ThePotatoOfFire said:
    I need to impose a second damage cap on all of my formulas to prevent them from going beyond 999,999 damage in a single hit. I know the basic idea of what I need, I just don't know how to write it so RMMV will understand it.
    Example:
    If (a.atk * 4) > 999,999, set damage value to 999,999

    How do I write this properly?
    Math.min(formula, 999999)
  5. Hey guys, I'm stuck with a simple damage formula. The skill I want to make is Shield Slam. The more defense (bigger/stronger) your shield, the more dmg.
    Formula : a.equips()[1].def * 20
    But it's always 0.
    I use YEP Equip Core and read somewhere that this plugin changes the way for the equip slots. How would be the correct formula?

    Thanks in advance
  6. Hey guys,

    An issue with a formula that uses a condition based on a variable. Here it is:

    v[42] >= 3 ? $gameTroop.members(1).atk * 4 - b.def * 2 : 25 + a.atk * 4 - b.def * 2

    Works fine as long as the variable doesn't have an assigned value. When it's given one, I get this error:

    Spoiler
    TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': float parameter 3 is non-finite.
    at TypeError (native)

    Wondering if it's something to with using $gameTroop.member(1) for atk param.
  7. @thepsyche
    Try members()[1], and don't forget this will only work if there is a members()[1] in the battle...
  8. @Waterguy of course. Thanks for the quick response. It worked. Why is it that with the $gameActors string I only need to include normal brackets, but with $gameTroop I need closed brackets and the ID in the square brackets?
  9. Really?
    Never tried without it for actors...
  10. Yeah! Here's a formula I have that works just fine:

    ($gameActors.actor(1).atk * 4) + ($gameActors.actor(2).atk * 4) - b.def * 2
  11. I'm trying to make a conditional skill but I am having no success with the formula.

    I want the skill to remove a particular state if the user is affected by this particular state. If the target is not affected by the state, then the skill would give a Defense buff.

    I've tested several versions of this formula if (b.isStateAffected(23)) {b.removeState(23); else {b.addBuff(3,5);}, but it just doesn't work. Some help would be appreciated.
  12. you're forgetting to close the {b.removeState(23);}
  13. Guys, how can I create a high damage, low accuracy attack? I'm lost with the formulas. Do I need to set state Normal Attack 100% first? Any advice is welcome.
  14. ddblue said:
    Guys, how can I create a high damage, low accuracy attack? I'm lost with the formulas. Do I need to set state Normal Attack 100% first? Any advice is welcome.

    You can always lower the success rate from the invocation box in the skill menu to reduce the accuracy. If it only succeeds 50% of the time it will only hit 50% of the time.
  15. I'm having a bit of trouble with applying a state through damage formulas. I would use the effects box but I only wan't the state to apply if the attack hits an elemental weakness.

    This is what I have so far:

    if (b.elementRate(2) > 1) {a.mat * 4 - b.mdf * 2 + b.addState(17);100} else {a.mat * 4 - b.mdf * 2}

    The problem is it doesn't factor in enemy state rates so the state always applies regardless of resistances or immunities.

    If anyone had a solution it'd be a huge help!
  16. When using Yanfly's Class Change Core, is it possible to assign damage constants to each unique class and have them scale with the character's level?

    Specifically, I'd like each class to have a physical damage constant and a magical damage constant which will be divisors, and I want the character's level to be the dividend. The quotient will be a multiplier which is then used in the general damage formula.

    Here's an example: a character using the Knight class has a physical damage constant of 12 and a magical damage constant of 30. At level 99, the Knight would have the following damage multipliers:

    Physical: (1 + 99)/12 = 8.33

    Magical: (1 + 99)/30 = 3.33

    At level 23, however, the Knight would only have a 2x multiplier on its physical damage, and its magical attacks would only deal 80% of the base damage.

    This system would naturally provide damage scaling for each class throughout the game. Monsters would likely use a different system based on their level alone.

    Is something like this possible to do with the base engine, or will I need plugins to achieve it? How can I script it?
  17. @Soryuju Making it scale with level is easy, as level is a usable command in the damage formula.
    (1+a.level)/12=X

    As far as providing a constant for each class, there are a couple of ways that I can think of doing this and each are rather complex.

    What I would recommend is using Yanfly's weapon unleash plug-in. http://yanfly.moe/2015/12/26/yep-51-weapon-unleash/
    From here you would have to make a unique attack for each class and use the notetag <Replace Attack: x> in the Class Notebox.

    Alternatively, you can write the damage formula to perform a check, I believe the syntax is as follows:
    a.isClass(ID)

    However, you may end up with a long and complex list.

    I recommend the weapon unleash unless someone suggests something better.
  18. @boikish

    Thanks for the response! If you don't mind, could you explain a bit more about using Weapon Unleash to set physical and magical class constants? I don't really understand what I could replace the attack command with that would create a scaling physical/magical damage multiplier for each of a class's offensive skills. Also, I'm not sure if this changes anything, but I'm also aiming to use the Subclass plugin, so I need whatever I solution I come up with to work as a set of permanent multipliers for all offensive skills in the game.

    For your second suggestion, what notetags/scripts do I need to assign the appropriate constants to that "ID" value for each class? Could you give me a brief example?

    Thanks again!
  19. @Soryuju so you want the constant to affect all skills, not just attack?
    In this case, I think it is best to use a plugin to create new parameters for those constants and change the value with each class.

    I myself created one, it is in the topic in my signature. Hopefully it helps.
  20. Joronjo said:
    I don't know if it works in MV the same, but in ace it would have been something like

    a.atk + (rand(4)+1) or

    a.atk + (rand(4.0)+1) if you wanted to use float values

    I worked on a random damage skills as well, I use the Math.random() function to generate a random number between 0 and 1. So, for example, if you wanna emulate a 6-sided die roll, you can do: Math.floor(6*Math.random())+1.
    It works like this: if you do 6*Math.random, you will get a random number between 0 and 6 (except 0 and 6 - in math terms, it's a number in the interval ]0,6[). The floor function (Math.floor) will round down the number to an integer, so the result will be an random integer from 0 to 5. Adding 1 will then result in an random integer from 1 to 6, like a 6-sided die roll would.

    So I created a physical attack that deals random damage to a target. The formula I used was:
    (Math.floor(6*Math.random())+2)*a.atk-2*b.def
    The resulting skill sometimes dealt a lot of damage, but other times it did less damage than a regular attack, just as I wanted.