Damage Formulas 101

● ARCHIVED · READ-ONLY
Started by Skunk 281 posts Page 2 of 15 View original ↗
  1. You should enclose what happens when the "if" is true in {}

    Also, using + between each "action" means it will try to add the result of .addState() to the damage value. I dont think thats a good idea and might even cause problems down the line

    I suggest to try transforming it into

    Code:
    if (b.def + b.agi <= (Math.randomInt(20) + 1 + a.mdf + a.mat)) {b.addState(43); Math.randomInt(8) + 1 + a.mdf}; else {0};

    See if it works or not.
  2. Engr. Adiktuzmiko said:
    You should enclose what happens when the "if" is true in {}

    Also, using + between each "action" means it will try to add the result of .addState() to the damage value. I dont think thats a good idea and might even cause problems down the line

    I suggest to try transforming it into

    Code:
    if (b.def + b.agi <= (Math.randomInt(20) + 1 + a.mdf + a.mat)) {b.addState(43); Math.randomInt(8) + 1 + a.mdf}; else {0};

    See if it works or not.

    This solved one of my problems, the spell is no longer applying the status on a miss. The problem is, that the spell no longer 'hits' anymore, always dealing 0 damage, and never applying the state. It would seem I still have work to do. (I even tried setting the enemy stats to 1's, and the battler's stats to never be low enough to miss, so it's not just bad RNG.)

    Thank you for helping, it's nice to see a supportive community :)
  3. If it always do 0, its probable that the formula has an error because the damage formula evaluation code is set to do 0 damage if an error occurs
  4. I hadn't actually figured that out. I changed the else to do 2 dmg, yet the spell still did 0, so it's just an error through and through. Unfortunately I haven't been able to fix it, but I found a neat trick using Yanfly's plug-in for damage over time, and put the damage formula into the state instead of the skill, and that seems to work. Thankfully it was a state set to only last for one round, so it works.

    Thank you again for the help :)
  5. What about an attack that gets stronger if any other party member is below 50% Hp or dead?

    Or an attack that crits if a variable is a certain number?
  6. Okay, so you can use a variable to alter a damage formula, but can you use a formula to change a variable? Also, do a skill's effects occur before or after a formula is executed (so you can use the newly changed variable in say a common event)?
  7. Just found this, thank you so much for sharing, this makes my life as person with Syntax Problems so much easier.
    ++good
  8. Oddball said:
    What about an attack that gets stronger if any other party member is below 50% Hp or dead?

    Or an attack that crits if a variable is a certain number?

    The first part is easily manageable using the array function .some

    Code:
    if (a.friendsUnit().members().some(function(member) {return member.hpRate() < 0.5})) 50; else 30;

    Where the 0.5 represents the 50% health. The 50 is the increased damage value, and the 30 is the reduced damage value.

    To address if any allies are dead you could use something like this (again, 50 is increased damage, 30 is reduced).

    Code:
    if (a.friendsUnit().deadMembers().length > 0) 50; else 30;

    Whether an attack is critical or not is decided Before the damage value is evaluated so would be difficult to control from the damage formula. You may want to look into a plugin to do this for you.

    MetalKing11417 said:
    Okay, so you can use a variable to alter a damage formula, but can you use a formula to change a variable? Also, do a skill's effects occur before or after a formula is executed (so you can use the newly changed variable in say a common event)?

    You can use this function to control the value of your variables

    Code:
    $gameVariables.setValue(x, y); damageFormula

    Where x = variable id
    y = value to be assigned
    damageFormula = your normal damage formula

    Providing you don't have any plugins altering things your common events should execute after the damage formula is evaluated.
  9. Having some issues getting the if/then in the damage formula to apply state. I want basically the same thing as an earlier post. If (1d20 + a.atk) >= (10 + b.def), apply state to defender.

    I tried, and failed, using the following. And a couple variations where I removed some of the () and spaced out the +1.

    if (a.atk + (Math.randomint(20)+1)) >= (b.def + 10) {b.addstate(3)} ; else{0} ;

    Where state 3 is a stun. Tried it with (3) and (0003) as listed in the database.

    That didnt work, just kept rolling 0 damage and not applying the state (had a.atk stat set to 20 and b.def set to 1, so should always apply). Tried both with and without using the semicolons. Any help appreciated.

    Edit - is it possible to use note tag instead of damage formula box to accomplish the desired effect?
  10. Hello!

    I can do just about anything with MV, but this combat coding has me feeling like my 6 year old trying to understand how algebra works....

    I am trying to turn (for fun) a old Grail Quest: Choose Your Own Adventure RPG book into a free to play MV game. I would like the combat in the game to mimic how it worked in the RPG book.

    So like this:

    1) Roll 2D6 (so generate a random number between 2 to 12)
    2) To HIT you opponent you need to roll higher than the weapon ATK value. (So if the ATK is 6, to hit you need to get a number higher than 6.)
    3) The DAMAGE done is equal to the DMG value of the weapon plus every point above the ATK value of what your just rolled. (So if the ATK value of the weapon used was a 6, and you rolled an 8, and the weapon has a DMG value of the weapon is 2, then you did 4 points of DMG.)
    4) Then deduct the DEFENSE value of any armor worn (if any at all) from the damage, to get the final damage done. (So if 4 DMG was done from the weapon, but the opponent has a DEFENSE value of 1, then only 3 points of total DMG is done!)

    So basically:
    IF ROLLED RESULT < ATTACK VALUE then MISSED
    IF ROLLED RESULT > ATTACK VALVE then ((ROLLED RESULT - ATTACK VALUE) + WEAPON DAMAGE) - DEFENSE VALUE = FINAL DAMAGE DONE

    EXAMPLE:
    Rolled a 8 ((8 rolled - 6 ATK) + 2 DMG) - 1 DEF = 3 total damage to opponent

    I was thinking of just eventing the combat if I couldn't figure out how to make it work through the normal combat system.
  11. I'm having issues with my formula. No matter what I do they always yield me 0 damage.
    Example of formula used
    ((8/16) * (level+a.mat)) * 6
    I've used variations of this with and without the brackets as well and still a 0
  12. @J-G in your formula, you've written "level".
    Whose level? a or b?
  13. Sorry I left that out. It's a's level
  14. If it's a's level then you need to write "a.level" otherwise it doesn't know who's level.

    So the formula would be
    Code:
    (a.level + a.mat) * 3

    Because of course "(8/16) * 6" simplifies to just 3
  15. Yeah, just tried it lol didn't realize I was leaving the "a." Part out haha now it works. Thanks so much
  16. Hi I'm after 2 things one has already been asked but didn't get a reply

    Is it possible to change a variable with a damage formula so I can make a skill that gets stronger the more it's used?

    Also is it possible to make a formula that does damage to an enemy and inflicts a state on the party aswell? I tried

    A. Addstate(poison) ; && a. Atk * 4 - b. Def * 2

    Any help would be much appreciated
  17. @Nofx670 -

    1) Yes, if its a game variable just do

    $gameVariables.set(ID,value)

    or if it isnt a GV, just do variable_name = value

    before the actual damage part of the formula.

    2) Yes, you are almost right, but the code to add state afaik is a.addState(State ID) not Addstate(state name)

    Also dont write && after the ;... You dont need &&
  18. Engr. Adiktuzmiko said:
    @Nofx670 -

    1) Yes, if its a game variable just do

    $gameVariables.set(ID,value)

    or if it isnt a GV, just do variable_name = value

    before the actual damage part of the formula.

    2) Yes, you are almost right, but the code to add state afaik is a.addState(State ID) not Addstate(state name)

    Also dont write && after the ;... You dont need &&

    I've tried both of those but they come back with no damage or states inflicted and don't change the variable when I check the debug window
  19. Your above message may have been typed by phone and I appreciate that predictive keyboards make writing code difficult, but if not you need to be careful of the case your typing in. You have a lot of upper case letters where you should be using lower case - this means that the engine isn't recognising the properties and is instead returning undefined, this won't give you any errors in the console because it's expected behaviour. This is likely the reason there's no damage.

    Regarding setting the game variable, the correct code is

    Code:
    $gameVariables.setValue(id, value);
    
    // eg.
    
    $gameVariables.setValue(1, 200);
    
    // Set variable 1's value to 200

    I can see no reason that the state codes should not work, unless there has been an error before hand and the damage formula has stopped evaluating. Ideally you want something that looks like this

    Code:
    a.addState(4); $gameVariables.setValue(1, 200); a.atk * 4 - b.def * 2;
  20. Silva said:
    Your above message may have been typed by phone and I appreciate that predictive keyboards make writing code difficult, but if not you need to be careful of the case your typing in. You have a lot of upper case letters where you should be using lower case - this means that the engine isn't recognising the properties and is instead returning undefined, this won't give you any errors in the console because it's expected behaviour. This is likely the reason there's no damage.

    Regarding setting the game variable, the correct code is

    Code:
    $gameVariables.setValue(id, value);
    
    // eg.
    
    $gameVariables.setValue(1, 200);
    
    // Set variable 1's value to 200

    I can see no reason that the state codes should not work, unless there has been an error before hand and the damage formula has stopped evaluating. Ideally you want something that looks like this

    Code:
    a.addState(4); $gameVariables.setValue(1, 200); a.atk * 4 - b.def * 2;

    Yea sorry that was predicted txt

    When typed in the skills box it is correct but still neither seem to work. If I remove the set variables or add state code it works and does basic damage.

    I'm wondering if the add state command isn't working because I'm trying to effect the 2 separate targets with the 1 formula.

    Thank you for your help