RMMV Damage Formula - ideas and help

Discussion in 'RPG Maker MV' started by Shaz, Oct 25, 2015.

  1. Silva

    Silva Scoobityboo Veteran

    Messages:
    268
    Likes Received:
    126
    First Language:
    English
    Primarily Uses:
    RMMV
    Yup, simply a plugin with one function to handle the damage formula. You could create multiple different damage formula functions within the same plugin though if you wanted to.

    The parameter "action" is used to reference the specific instance of the action the function is working on by having the function call pass the value "this" (I'm sure I posted an example earlier). What this does is opens up the use of Game_Action functions that already exist in the engine (you can find these by looking in rpg_objects.js). In the previous example we were using

    Code:
    Game_Action.prototype.isPhysical()
    Game_Action.prototype.isMagical()
    to check if the action itself was physical or magical, in the damage formula function these looked like this

    Code:
    action.isPhysical()
    action.isMagical()
     
    jetboost likes this.
  2. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Yes you did post an example earlier now that you point it out it is clear to me, I was thinking to much about it.

    And also yes this is what I meant, this would have saved a lot of time in my case if I knew earlier.
    Every weapon in my project has it's own scaling and I wanted to remove it from the notebox because I have 13~ different weapon types, it would be to much I would want to put in there.
    So doing it your way would have been better.

    Thank you again.
     
    Silva likes this.
  3. jonthefox

    jonthefox Veteran Veteran

    Messages:
    1,284
    Likes Received:
    442
    Location:
    NYC
    Hi there. Is there a way to use the damage formula to do the following:

    A skill does single target damage, and it has 3 different outcomes based on the amount of damage the target takes. If the target takes less than 25% of its maxhp in damage; it takes the damage and no state is added. If the target takes more than 25% but less than 50% of its maxhp in damage; it takes the damage and state A is added. If the target takes more than 50% of its maxhp in damage; it takes the damage and state B is added.

    By the way, I was originally doing something similar to this (but only 2 possible outcomes) through a conditional based on the damage formula and comparing that to b.maxhp, but I realized that wasn't working correctly because it doesn't factor in any defensive buffs or states that the target might have which reduces teh damage it takes. So I need the condition to be based off the actual damage taken. Thank you in advance if anyone can help me with this!
     
  4. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Yes this is possible with the use of Yanfly Skill core plugin.
    Register enemies current health within( a) <before eval></before eval> and within <after eval></after eval> you check the enemies current health again(var b) then a conditional "if(a-b >= enemies max health/4){ etc.}".

    This should work, haven't created a skill like this before.
     
    Last edited: Jun 28, 2019
  5. Cah

    Cah Villager Member

    Messages:
    8
    Likes Received:
    4
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Hello, I am looking for help with this formula on if there is anything in it's structure that I missed or something that doesn't need to be there or if it can just be shortened/simplified:
    Code:
    Math.round(a.atk * 0.35 + a.luk) + Math.round(Math.randomInt(a.level)+1 + Math.round(Math.randomInt(b.level)+1 / 2))
    I'm going to do my best with explaining exactly what I am aiming to achieve with it by breaking it down into 2 parts. Also I omit "b.def & b.mdf" in the formula because I am using Yanflys ArmorScaling plugin which deals with the targets defenses in damage calculation. I used w3schools.com as a code reference.

    Part 1: "Math.round(a.atk * 0.35 + a.luk)" - using 35% of the users attack stat in the formula rounded to nearest number, then adding the users entire raw luk stat number to that.
    Part 2: "+ Math.round(Math.randomInt(a.level)+1 + Math.round(Math.randomInt(b.level)+1 / 2))" - picking a random number between 1 and the users level, then adding that with a random number between 1 and the targets level, then adding those randomly chosen numbers together, then dividing that by 2 (finding the mean) rounded to nearest number and then finally adding that to part 1 of the formula finishing it off.

    The idea is to not have any decimals in the finished number and for part 1 & part 2's minimum possible number to always be at least 1.

    I am new to javascript & still learning so let me know if there needs to be any more explanation or clarification.
     
    Last edited: Jul 20, 2019
  6. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    You have explained it well and so far I can see it should work if you also have the plugin” Yanfly enemy levels “otherwise b.level should not work and you might need to use the enemylevel function of that plugin instead of b.level though i’m not sure.

    You could also use only one Math.round function and put the entire formula inside of it or if you also use the plugin damage core from Yanfly and do something like this “value = formula; Math.round(value)”

    You can make use of ternary operators to shorten conditional statments, w3schools also covers the use of this a bit.
    However you don’t need that for this one.

    Hope it helps.
     
    Cah likes this.
  7. Cah

    Cah Villager Member

    Messages:
    8
    Likes Received:
    4
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Ah yea, I do have Yanfly's EnemyLevels plugin. I must have forgot that that plugin uses that function since I've used it for so long haha.

    I had a feeling that I only needed one Math.round but figured I'd just leave the formula how it was and know for sure by asking. I'll try out that in DamageCore though as I use that too, I'm assuming I would adjust the last part of the damage formula, right? I'm using DamageCore's default plugin parameters btw. For me the last one is
    Code:
    value = this.applyMinimumDamage(value, baseDamage, target);
    So I would change it to this?
    Code:
    value = this.applyMinimumDamage(Math.round(value, baseDamage, target));
    Or would I just add "value = formula; Math.round(value)" as a completely new damage step somewhere towards the end?

    Didn't even know about ternary operators, I'll have to study more about those as I'm still very new, the fundamentals if you will.
     
    jetboost likes this.
  8. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    I would do it like "value = formula; Math.round(value)" this yeah.
    You store the outcome of your formula into value and then Math.round it.

    Because I don't know from where the function applyMinimumDamage comes from or what it would do, so I prefer to stay clear of it till I do know but that is likely different in your case.

    Your way of doing it should also work but not in the way you changed it.
    You gave Math.round() 3 values to work with "value, baseDamage, target".
    This way:
    Code:
    value = this.applyMinimumDamage(Math.round(value), baseDamage, target);
    
    It ought to work.
     
    Cah likes this.
  9. Cah

    Cah Villager Member

    Messages:
    8
    Likes Received:
    4
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Yea I'm not positive what MinimumDamage is used for either, I think it might have to do with one of Yanfly's other addons but for me looks like it's just ignored in calculation. However, it was the very last step in damage so that's why I listed it.

    Finally got around to actually testing it out in RM and it works! I decided to also put "Math.randomInt(a.level)+1 + Math.randomInt(b.level)+1 / 2" into DamageCore and it works great (apparently "a.level" & "b.level" can be used in DamageCore, so that's pretty cool). Now it's just:
    Code:
    a.atk * 0.35 + a.luk
    Thanks for the help I appreciate it, I managed to slim the formula down more than I was expecting to.
     
    jetboost likes this.
  10. jjleroy

    jjleroy I love bananas Veteran

    Messages:
    140
    Likes Received:
    31
    Location:
    Germany
    First Language:
    German, English
    Primarily Uses:
    RMMV
    ---
     
    Last edited: Jul 31, 2019
  11. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    You would have to register "target.something" in an variable at the start of a battle that would mean you would have to create an common event to run at the start of an battle that checks every troop&actor and put the value of every stat into an object like this
    Code:
    $gameVariables.setValue(100,{$gameParty._actors[x]:{$gameActors.actor($gameParty._actors[x]).stat}})
    
    If x == 0, you will be inside the object of your first actor in your party and from there you can grab all its stats.
    Just change "stat" into the correct abbreviation.

    And after the battle you would have to run an common event to set all the values back to the ones registered.

    Do you understand how to do it like this? If not I can write it entirely down but that will take some time.
     
    jjleroy likes this.
  12. jjleroy

    jjleroy I love bananas Veteran

    Messages:
    140
    Likes Received:
    31
    Location:
    Germany
    First Language:
    German, English
    Primarily Uses:
    RMMV
    @jetboost thank you for the solution!!!, that was very well explained! It works perfectly now :)
     
    jetboost likes this.
  13. Rigor Mortex

    Rigor Mortex Mankind's Mirror Veteran

    Messages:
    56
    Likes Received:
    1
    Location:
    Dark World
    First Language:
    English
    I have two skill functions I haven't been able to figure out the formatting for.
    1. The first starts by checking for the presence of a specific state (70) on the user; if it exists, then there is a 50% (1/2) chance that the skill will ignore 1/3 of the current target's relevant defensive stat. Obviously(?), this chance would be individualized so that multiple enemies would each have their own respective chance of their defensive stat partly being ignored. (a.mat/4) * 24 - (a.isStateAffected(70) ? b.mat * 2 / 3 * 4 : b.mat * 4) is as close as I got to what I wanted; my attempts to incorporate the random chance always returned 0 damage.
    2. The second inflicts ONE of seven status problems, chosen randomly, to the current target. This would be individualized, much like the previous, and should not ignore any State Rates the target has. I haven't even attempted this one yet, as my searches for anything similar never helped.
    Is it possible to do these?
     
  14. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Both are possible through the use of Yanfly's skill core plugin.
    Though I will not write it down using ternary operators for the sake of better readability.

    1.
    Code:
    value = a.mat/4) * 24 ;
    if(a.isStateAffected(70)== true){
    if(Math.randomInt(random)+1=<chance) {value =  value - b.mat * 2 / 3 * 4;} else{value = value-b.mat * 4;}
    }
    else{value = value-b.mat * 4;}
    Just determine a value for random and chance if random ==10 and chance ==1, you would have a 1 out of 10 chance.
    2.
    Code:
    <After Eval>
    var state = 15 ;
    var basechance = 100;
    var roll = Math.randomInt(100) + 1;
    var chance = basechance * target.stateRate(state) ;
    if(roll < chance && target.result().isHit() ){target.addState(state);}
    </After Eval>
    This should do.

    EDIT: at section 1. forgot to store the new value inside "value" (value =)
     
    Last edited: Aug 3, 2019
  15. Rigor Mortex

    Rigor Mortex Mankind's Mirror Veteran

    Messages:
    56
    Likes Received:
    1
    Location:
    Dark World
    First Language:
    English
    I might just be dense, but the instructions are unclear. Would you be able to elaborate? All I think I've figured out is inputting the following into the first skill's Notes box.
    Code:
    <Pre-Damage Eval>
    value = a.mat/4) * 24 ;
    if(a.isStateAffected(70)== true){
    if(Math.randomInt(2)+1=<1) {value =  value - b.mat * 2 / 3 * 4;} else{value = value-b.mat * 4;}
    }
    else{value = value-b.mat * 4;}
    </Pre-Damage Eval>
    I'm also unsure I was clear enough with the second, given I don't know code, but I'll mention it just to be on the safe side: The "seven status problems" are seven specific ones, namely states 5, 6, 7, 8, 9, 10, and 13.
     
  16. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    No problem I'll try to make it clearer.
    The first one should work it's just a matter of testing.

    note* Math.randomInt(x) is an function build-in RPG maker MV that returns a random rounded(down) value "between" 0 and x.(As it is thus rounded down the value can never be x)
    And the 2nd one I seem to have forgotten a part.

    Code:
    <After Eval>
    var state = [1,2,3,4,5,6] ;
    var rndstate = Math.randomInt(6);
    var basechance = 100;
    var roll = Math.randomInt(100) + 1;
    var chance = basechance * target.stateRate(state[rndstate]) ;
    if(roll < chance && target.result().isHit() ){target.addState(state[rndstate]);}
    </After Eval>
    note2* Arrays: An array is an variable that con store multiple values in this case the variable state has 5 values because we are counting 0 as well for arrays.
    You can access the individual values in this array by typing state[0] to get 1 or state[5] to get the value 6.
    As we know Math.randomInt() returns a value between 0 and it's given number rounded down, this means it can return the values 0, 1, 2, 3, 4 and 5.
    So in this case the variable "state" is the array while the variable "rndstate" will be pointing to an value inside the array.

    Extra: Javascript has some methods that you can use I will try to explain a bit of the .length method to you.
    .length is simply a method that returns the length of an variable, giving you different results depending on what kind data you have stored inside this variable.
    In our case we have created an array called "state" and when we say state.length it will return the amount of values stored within this array (not including 0) thus it would return 6.

    So if you would use this:
    Code:
    <After Eval>
    var state = [1,2,3,4,5,6] ;
    var rndstate = Math.randomInt(state.length);
    var basechance = 100;
    var roll = Math.randomInt(100) + 1;
    var chance = basechance * target.stateRate(state[rndstate]) ;
    if(roll < chance && target.result().isHit() ){target.addState(state[rndstate]);}
    </After Eval>
    You would be able to add as much states as you want in the array "state" without having a need to change the rest.

    Hope it helps, I also suggest doing a bit of reading up on javascript at w3schools( or a similar website) they also cover all what I have mentioned.
     
  17. Petrus906

    Petrus906 Villager Member

    Messages:
    6
    Likes Received:
    2
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    I'm having a problem with a formula I tried to use... it's about inflicting an status on enemy but only if he meets a condition (on my case, Undead enemies). So it is like this:
    • b.isStatusAffected(Undead)? b.addStatus(id) : 1000 - b.luk;
    I managed for it to kinda work, but the undead enemy gets the status and becomes immortal. I tested with different status but it still happened. When I tweak the formula a little the enemy can be killed, but if that condition is not met it deals 0 damage....
    I'm pretty sure there isn't anything abnormal on the skill or status, so maybe it's a plugin?
     
  18. Rigor Mortex

    Rigor Mortex Mankind's Mirror Veteran

    Messages:
    56
    Likes Received:
    1
    Location:
    Dark World
    First Language:
    English
    I've tested it several ways, but it doesn't seem to work. Having no formula just returns 0 damage, and having the formula pictured below only operates off what's in the Formula bar. I've tested with all plugins turned on, with only Skill Core and Core Engine turned on, and only Skill Core turned on. I also tested it with both =<1, and =<2.
    [​IMG]
    (As an aside, the forum wouldn't let me just upload the spoiler'd image; kept saying "There was a problem uploading your file.")
     
  19. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Yeah I it seems I forgot a ")" look at the 2nd sentence "a.mat/4)" remove that one.
    And the "=<" has to be this "<="at line 4.
     
  20. jetboost

    jetboost Veteran Veteran

    Messages:
    81
    Likes Received:
    26
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    You have typed status instead of state?
    Is it a plugin you use that uses that?
     

Share This Page