Damage even when countering

Sorry if this is asked before but i know as much about java script as i do rocket science.  Where can i find the Calculation where it negates the damage you take before a counter attack?


I would change it like this. 


get hit, take damage, and then counter. (also if both targets had 100% counter rate i'd like them to slug it out till death)


but if the target dies before countering that's fine. no death counters for you.


Switching to MV i don't know where this is to change it anymore. Also what i might need to change it to would be 150% helpful as well. as i'm not sure what i would be looking at script wise and i don't want to mess anything up.


Sorry if this is posted in the wrong spot.


Appreciate any help ahead of time.
The below is the related codes in the default RMMV codebase:


BattleManager.invokeAction = function(subject, target) {
this._logWindow.push('pushBaseLine');
if (Math.random() < this._action.itemCnt(target)) {
this.invokeCounterAttack(subject, target);
} else if (Math.random() < this._action.itemMrf(target)) {
this.invokeMagicReflection(subject, target);
} else {
this.invokeNormalAction(subject, target);
}
subject.setLastTarget(target);
this._logWindow.push('popBaseLine');
this.refreshStatus();
};

BattleManager.invokeNormalAction = function(subject, target) {
var realTarget = this.applySubstitute(target);
this._action.apply(realTarget);
this._logWindow.displayActionResults(subject, realTarget);
};

BattleManager.invokeCounterAttack = function(subject, target) {
var action = new Game_Action(target);
action.setAttack();
action.apply(subject);
this._logWindow.displayCounter(target);
this._logWindow.displayActionResults(subject, subject);
};
Code:
Game_Action.prototype.apply = function(target) {
    var result = target.result();
    this.subject().clearResult();
    result.clear();
    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);
    }
};




In RMVXA I've made the DoubleX RMVXA Counterattack Edit having the feature you want, and I'm still struggling with converting it into the RMMV plugin counterpart lol


Anyway, the below is the related codes of that script:


class Game_Battler < Game_BattlerBase

#----------------------------------------------------------------------------|
# (v1.03a+)Alias method: item_cnt |
#----------------------------------------------------------------------------|
alias item_cnt_counterattack_edit item_cnt
def item_cnt(user, item)
# This part is rewritten by this script to negate hit upon CNT if CNT_Negate_Hit is true
DoubleX_RMVXA::Counterattack_Edit::CNT_Negate_Hit ? item_cnt_counterattack_edit(user, item) : 0
#
end

#----------------------------------------------------------------------------|
# (v1.01a+)New method: invoke_counter_attack? |
#----------------------------------------------------------------------------|
def invoke_counter_attack?
@invoke_counter_attack
end # invoke_counter_attack?

end # Game_Battler

class Scene_Battle < Scene_Base

#----------------------------------------------------------------------------|
# (v1.01a+)Alias method: apply_item_effects |
#----------------------------------------------------------------------------|
alias apply_item_effects_counterattack_edit apply_item_effects
def apply_item_effects(target, item)
apply_item_effects_counterattack_edit(target, item)
# This part is added by this script to invoke cnt upon mev or !CNT_Negate_Hit with chance cnt
invoke_counter_attack(target, item) if target.mev_invoke_cnt? && target.invoke_counter_attack? || !DoubleX_RMVXA::Counterattack_Edit::CNT_Negate_Hit && rand < target.item_cnt_counterattack_edit(@subject, item)
#
end # apply_item_effects

end # Scene_Battle


Converting it into the RMMV counterpart would be something like this:


BattleManager.invokeNormalActionCntEdit = BattleManager.invokeNormalAction;
BattleManager.invokeNormalAction = function(subject, target) {
this.invokeNormalActionCntEdit(subject, target);
// Added to have probability of cnt to invoke cnt if it doesn't negate hit
if (Math.random() >= this._action.itemCntEdit(target)) { return; }
this.invokeCounterAttack(subject, target);
//
}; // BattleManager.invokeNormalAction

Game_Action.prototype.itemCntEdit = Game_Action.prototype.itemCnt;
Game_Action.prototype.itemCnt = function(target) {
return 0; // Rewritten to stops the cnt from negating hit
}; // Game_Action.prototype.itemCnt


I haven't tested the above conversion though, so you might want to exercise caution if you do try that 🙂
Have you seen this?




There is also
Thanks i'll try these in a mock game and then post my results in an edit to this post.


**Edit, i ended up useing himeworks plugin. Thanks for the help!

Original thread: https://forums.rpgmakerweb.com/threads/damage-even-when-countering.55271/