MV Custom Battle Popup Plugin Help

Hi guys,

I'm working on a plugin that expands the damage popup, and I want to show text that displays the target's susceptibility to certain elements (resist, weak, immune). The difficulty I'm having is figuring out where to calculate the target's element rate. I'm pretty sure it involves the Game_Action object, but I don't have enough experience to figure it out. Any help would be appreciated!
The difficulty I'm having is figuring out where to calculate the target's element rate. I'm pretty sure it involves the Game_Action object, but I don't have enough experience to figure it out. Any help would be appreciated!
Game_Actions do have the function to calc element rate (see calcElementRate()), but since youre working with popups you may want to make it so that when the damage is being executed you also pass the rate to the target's Action_Result to use for the popup. depends on how youre going about it
Game_Actions do have the function to calc element rate (see calcElementRate()), but since youre working with popups you may want to make it so that when the damage is being executed you also pass the rate to the target's Action_Result to use for the popup. depends on how youre going about it
That's exactly what I'm having trouble figuring out. I want to pass the element rate to Action Result, but I don't know how to do that.

For some extra context, I'm using Yanfly's Battle Engine Core.

EDIT: I just tried adding some parameters to Action_Result and a method to change them, and it seems to work. Here's what I did:

JavaScript:
Game_Action.prototype.getElementRate = function(target){
    var elementRate = 1 * this.calcElementRate(target);
    console.log(elementRate);
    return elementRate;
};

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();
    result.elementImmune = (this.getElementRate(target) === 0);
    result.elementResist = (this.getElementRate(target) > 0 && this.getElementRate(target) < 1);
    result.elementWeak = (this.getElementRate(target) > 1);
    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);
    }
    console.log(result);
};

Game_ActionResult.prototype.clear = function() {
    this.used = false;
    this.missed = false;
    this.evaded = false;
    this.physical = false;
    this.drain = false;
    this.critical = false;
    this.success = false;
    this.hpAffected = false;
    this.elementImmune = false;
    this.elementResist = false;
    this.elementWeak = false;
    this.hpDamage = 0;
    this.mpDamage = 0;
    this.tpDamage = 0;
    this.addedStates = [];
    this.removedStates = [];
    this.addedBuffs = [];
    this.addedDebuffs = [];
    this.removedBuffs = [];
};
Is this a good way to go about it?
its a way that would work. you just need change the popup code to read those. personally, i would have just copied the rate into a single property and change the displayed text based on its value (===0, <1, >1) since a target can only be immune, resistant, weak, or neither the way your code is set up, but so long as youre handling the checks for the 3 properties properly it shouldnt be a problem
its a way that would work. you just need change the popup code to read those. personally, i would have just copied the rate into a single property and change the displayed text based on its value (===0, <1, >1) since a target can only be immune, resistant, weak, or neither the way your code is set up, but so long as youre handling the checks for the 3 properties properly it shouldnt be a problem
OK, I just did that. The text popup works okay, but it's overlapping with the damage numbers, and changing the y-coordinates doesn't seem to do anything.
Here's what I did for the crit text (the code's essentially the same for all of them):

JavaScript:
Sprite_Damage.prototype.createCrit = function(){
    var w = this.digitWidth();
    var h = this.digitHeight();
    var sprite = this.createChildSprite();
    sprite.setFrame(4 * w, 5 * h, 6 * w, h);
    sprite.y = -50;
    sprite.dy = 0;
};

And here's how I call the popups:
JavaScript:
Sprite_Damage.prototype.setup = function(target) {
    if(Imported.YEP_BattleEngineCore){
        this._result = target.shiftDamagePopup();
        var result = this._result;
    }
    else var result = target.result();
    if (result.missed || result.evaded) {
        this.createMiss();
    } else if (result.hpAffected) {
        if (result.elementRes === 0){
            this.createImmune();
        } else if (result.elementRes > 0 && result.elementRes < 1){
            this.createResist();
        }
        else if (result.elementRes > 1){
            this.createWeakness();
        }
        this.createDigits(0, result.hpDamage);

    } else if (target.isAlive() && result.mpDamage !== 0) {
        this.createDigits(2, result.mpDamage);
    }
    if (result.critical) {
        this.createCrit();
        this.setupCriticalEffect();
    }
};
changing the y-coordinates doesn't seem to do anything.
the movement code for the default popups should prevent changes made there to the y property from doing anything. its constantly updating. without making separate functions for the extra popups to use or changing the math, you could just add an offset property to the new popups and then use it in the movement code.

Code:
Sprite_Damage.prototype.createCrit = function(){
    var w = this.digitWidth();
    var h = this.digitHeight();
    var sprite = this.createChildSprite();
    sprite.setFrame(4 * w, 5 * h, 6 * w, h);
    sprite.dy = 0;
    sprite.yOffset = h;
};

Sprite_Damage.prototype.updateChild = function(sprite) {
    sprite.dy += 0.5;
    sprite.ry += sprite.dy;
    if (sprite.ry >= 0) {
        sprite.ry = 0;
        sprite.dy *= -0.6;
    }
    sprite.y = Math.round(sprite.ry) + (sprite.yOffset || 0);
    sprite.setBlendColor(this._flashColor);
};
That did the trick. Thanks!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/custom-battle-popup-plugin-help.182061/