Howto: Reverse healing items/skills to damage

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

kiriseo

Veteran
Veteran
Joined
Oct 27, 2015
Messages
245
Reaction score
82
First Language
German
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
 
Last edited by a moderator:

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
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);};
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top