Howto: Reverse healing items/skills to damage

I messed around in the:

Game_Action.prototype.apply()

Game_Action.prototype.applyItemEffect()

// Apply damage to the formula, if not already.if (target.isUndead && (effect.code == Game_Action.EFFECT_RECOVER_HP)){  if (item.damage.formula == '0')  item.damage.formula = effect.value2;}
Code:
// switch heal to damagevar alias_silv_undead_Game_Action_hasItemAnyValidEffects = Game_Action.prototype.hasItemAnyValidEffects;Game_Action.prototype.hasItemAnyValidEffects = function(target){	var item = this.item(); // JsonEx.makeDeepCopy( // cloning is not required because these items are new objects and are not the database itself.	if (target.isUndead && ('invert_for_undead' in item.meta))//target.isStateAffected(Silv.Undead.StateID) // todo: find out why RM deletes my state...	{		if (item.code == Game_Action.EFFECT_RECOVER_HP)		{			item.code = Game_Action.HITTYPE_CERTAIN;		}	}		return alias_silv_undead_Game_Action_hasItemAnyValidEffects.apply(this, arguments);;};
But I can't find the right spot to alias and to reverse recover/damage. I know it's super simple but I just can't find the right spot. I'm sure that this can be done with ~2 alias methods and I know that I'm close but just not close enough.
You could alias this function to run your check and invert the value for skills:

Just multiply the value with (-1) if it should invert the heal to damage for undead targets.

Game_Action.prototype.executeDamage = function(target, value) { var result = target.result(); if (value === 0) { result.critical = false; } if (this.isHpEffect()) { this.executeHpDamage(target, value); } if (this.isMpEffect()) { this.executeMpDamage(target, value); }};So it looks smth. like this:

var alias_silv_undead_Game_Action_executeDamage = Game_Action.prototype.executeDamage;Game_Action.prototype.executeDamage = function(target, value) { var item = this.item(); var newValue = value; if (target.isUndead && ('invert_for_undead' in item.meta)) { newValue *= -1; } alias_silv_undead_Game_Action_executeDamage.apply(this, target, newValue);};Oh, and you don't need to change the effect to Game_Action.EFFECT_RECOVER_HP.

For Healing Items, you could alias this function:

Game_Action.prototype.itemEffectRecoverHp = function(target, effect) { var value = (target.mhp * effect.value1 + effect.value2) * target.rec; if (this.isItem()) { value *= this.subject().pha; } value = Math.floor(value); if (value !== 0) { target.gainHp(value); this.makeSuccess(target); }};and check there for the undead state to change the healing to damage
Thanks a lot. By making the executeDamage-damage negative I also figured out to make the itemEffectRecoverHp-value negative as well. I got it fully working now thanks. Later today I guess I'll release a free 'undead script'.

The good thing about these 3 aliases is that it also automatically works for skills by just adding: || item.damage.type == 3.

Full solution:

Code:
var alias_silv_undead_Game_Action_executeHpDamage = Game_Action.prototype.executeHpDamage;Game_Action.prototype.executeHpDamage = function(target, value){    if (target.isUndead && (('invert_for_undead' in this.item().meta))) { value *= -1; }    alias_silv_undead_Game_Action_executeHpDamage.call(this, target, value);};var alias_silv_undead_Game_Action_itemEffectRecoverHp = Game_Action.prototype.itemEffectRecoverHp;Game_Action.prototype.itemEffectRecoverHp = function(target, effect){    var newEffect = JsonEx.makeDeepCopy(effect);    if (target.isUndead && ('invert_for_undead' in this.item().meta))    {        newEffect.value1 *= -1;        newEffect.value2 *= -1;    }    alias_silv_undead_Game_Action_itemEffectRecoverHp.call(this, target, newEffect);    };// Make sure that healing-potions & healing-skills can be used on undead-characters with full hpvar alias_silv_undead_Game_Action_hasItemAnyValidEffects = Game_Action.prototype.hasItemAnyValidEffects;Game_Action.prototype.hasItemAnyValidEffects = function(target){    var item = this.item(); // cloning is not required because these items are new objects and are not the database itself. // var item = JsonEx.makeDeepCopy(this.item());    if (target.isUndead && ('invert_for_undead' in item.meta)) //target.isStateAffected(Silv.Undead.StateID)    {        console.log(item);        if (item.effects.some(function (effect) { return effect.code == Game_Action.EFFECT_RECOVER_HP; } ) || item.damage.type == 3) // 3 == HP Recover        {            return true;        }    }        return alias_silv_undead_Game_Action_hasItemAnyValidEffects.apply(this, arguments);};

Original thread: https://forums.rpgmakerweb.com/threads/howto-reverse-healing-items-skills-to-damage.53432/