State Not applying Critical on first attack [Solved]

Discussion in 'RPG Maker MV' started by Jory4001, Jun 8, 2016.

  1. Jory4001

    Jory4001 Veteran Veteran

    Messages:
    80
    Likes Received:
    17
    Location:
    Canada
    First Language:
    English
    I have been having problems with a formula.


    I have reduced it to "a.addState(a); 10" for testing purposes.


    State(a) increases critical chance by 100%


    The state gets applied to the actor as it's icon shows up, however the damage dealt does not crit, it stays "10"


    If I make the skill target more enemies or do multiple hits, the first hit does 10 damage, and the rest of the hits apply the critical multiplier properly.


    I made changed the state to have "atk +1000%" instead of Crit with the formula  "a.addState(a); a.atk" to see if it reproduced the same results, but ALL attacks including the first had the increased damage.


    I am using Yanfly's BattleEngineCore and CriticalControl, I have looked through both and cannot find a reason as to why this is.


    My only explanation for this behavior is that the Xparam changes with states are applied after damage and BaseParam changes are applied before even if the state is affecting them graphically. ***Edit*** I can confirm this is the behavior as other Xparam changes like +/- Hit are not affected by the first attack either, but all BaseParam changes are.


    ***Edit*** The behavior is duplicated in a fresh game with no Plugins.


    Any help with this would be awesome!


    Jory.


    Edit* Urgh, I was inside the "Damage Formula Ideas & Help" page and the options were "Ask a Question" and "Answer a Question"... I thought "asking" would still put it in that forum topic. Apparently not... Guess I know for next time.
     
    Last edited by a moderator: Jun 8, 2016
    #1
  2. stupid enough to like FF13

    stupid enough to like FF13 Veteran Veteran

    Messages:
    587
    Likes Received:
    316
    First Language:
    English
    The reason this happens is because, on a successful hit, the code checks for critical before carrying out the damage formula. The damage formula will add the state to raise critical chance to 100% before calculating the base damage, but it has already decided whether or not the attack critically hits before executing the damage formula.


    If you're trying to create a skill that always critically hits, use this in the damage formula:

    Code:
    b.result().critical = true
     
    #2
  3. Jory4001

    Jory4001 Veteran Veteran

    Messages:
    80
    Likes Received:
    17
    Location:
    Canada
    First Language:
    English
    Awesome, I found the eval of the damage formula, evaluating the formula before hit is calculated allows the Hit and Crit changes to affect the skill immediately.


    Then re-evaluating afterwards to adjust damage if that crit took place!


    Now I can have a skill what has a natural increased chance to hit or crit! Your "b.result().critical = true" is nice to know but I didn't want absolutes I wanted a skill that has an increased chance to hit and crit by only a %.


    Thanks for the Help!


    For those looking to adjust this themselves inside rpg_objects.js

    Code:
    Game_Action.prototype.apply = function(target) {
        var result = target.result();
        this.subject().clearResult();
        result.clear();
        var JoryValue = this.makeDamageValue(target, result.critical);  //Jory Edit - Added this line to eval Damage formula before Hit and Crit Calculations
        // allows states applied that increase hit and crit to affect the skill being used immediately.
        result.used = this.testApply(target);
        result.missed = (result.used && Math.random() >= this.itemHit(target));
        result.evaded = (!result.missed && Math.random() < this.itemEva(target));
        result.physical = this.isPhysical();
        result.drain = this.isDrain();
        if (result.isHit()) {
            if (this.item().damage.type > 0) {
                result.critical = (Math.random() < this.itemCri(target));
                var value = this.makeDamageValue(target, result.critical);
                this.executeDamage(target, value);
            }
            this.item().effects.forEach(function(effect) {
                this.applyItemEffect(target, effect);
            }, this);
            this.applyItemUserEffect(target);
        }
    };
     
    #3

Share This Page