Make user gain no TP if skill deals 0 damage?

By default, if an actor hits an enemy with an elemental skill (with any amount of TP gain) and it nulls that element, the actor still gains that amount of TP. How can I prevent this from happening?
That will need a plugin as the TP gain is completely independent of damage done by default.

I don't know if yanfly's TP plugin can do that either because that is a request I never heard before.
So you might have to request a custom plugin for that.
It's a bit of a tricky one, because that function is embedded inside of Game_Action.apply(), which is overwritten by a bunch of plugins.

So it depends on what plugins you're using in your project.

The default function looks like this:
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);
    }
};

The bit you care about is the very last thing, applyItemUserEffect(). So if you're not using any plugins, you can copy this into a text editor, save it as a *.js file, and include it as a plugin:
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 is the line I'm adding vvvv
        if (value>0)
            this.applyItemUserEffect(target);
    }
};

If you are using any plugins that mess with this, like freaking tons of the Yanfly library and almost anything else that changes battle...you're gonna have to run a search in your plugin folder for Game_Action.prototype.apply - see which plugin is the lowest on your list in the plugin manager, and add the line I added above in that file.

You may be able to do this in Yanfly's Enhanced TP plugin.
Thank you a lot!
Unfortunately for myself I'm a heavy plugin user, so finding the one(s) I could modify without breaking things would be a hassle. I'll leave things as they are.

I did find a very makeshift workaround through Yanfly's Element Core, setting an enemy's elemental rate to 200% but also making it absorb that element. This does occasionally heal the enemy for exactly +1 HP, but that's negligible. That did not end up working, so I'll just let this slide.

Oh, another thing:
Code:
Game_Action.prototype.applyItemUserEffect = function(target) {
    var value = Math.round(this.item().tpGain * this.subject().tcr);
    this.subject().gainSilentTp(value);
};
Can this part itself be modified in some way? Such as also being multiplied by the target's element rate?

Original thread: https://forums.rpgmakerweb.com/threads/make-user-gain-no-tp-if-skill-deals-0-damage.161336/