I don’t think so. At least not in the OnDamaged script; because there’s no way to convert effects after they’ve been constructed, or bypass effects after they’ve been applied. Undead heal/harm is handled well before it gets to the OnDamaged script: basically a spellscript (eg. CureLightWounds or InflictLightWounds) will check if its effect is going to be applied to an undead creature and it constructs an appropriate opposite-effect there.
So i imagine that what you’re suggesting would sorta need to do the same thing. That is, in any script that a negative damage effect is going to be constructed and applied, do EffectHeal() instead.
Ok, thanks. I noticed that i misinterpreted the ability that i’m trying to create now that you mentioned the heal/harm scripts from the healing/cure wounds spells. It was very late when i was doing this abilities(the player gets some lich’s powers temporarily).
The ability reads as follow: Undead Healing: Negative energy (such as that of an inflict spell) heals you rather than damaging you. If you are a living creature, positive energy (such as a cure spell) still heals you as well.
This is very promising. Also works with weapons that have Negative Energy damage. I left the debug code for those that wish to check my work.
// ondamaged_neg
/*
Place this on the creature's OnDamaged event.
Set the creature to immortal TRUE.
*/
void main()
{
object oCreature = OBJECT_SELF;
int nHP = GetCurrentHitPoints();
int nTotalDMG = GetTotalDamageDealt();
int nDTN = DAMAGE_TYPE_NEGATIVE;
int nNeg = GetDamageDealtByType(nDTN) < 0 ? 0 :GetDamageDealtByType(nDTN);
int nHeal = nNeg * 2;
// object oPC = GetFirstPC();
// SendMessageToPC(oPC, "TotalDamage: " + IntToString(nTotalDMG));
// SendMessageToPC(oPC, "CurrentHP: " + IntToString(nHP));
// SendMessageToPC(oPC, "NegativeDMG: " + IntToString(nNeg));
// Kill the creature if its HP is 1 and non-DAMAGE_TYPE_NEGATIVE is more than what could be healed.
if (nHP == 1 && nTotalDMG - nHeal > 0)
{
SetImmortal(oCreature, FALSE);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oCreature);
return;
}
// Heal the creature if it takes DAMAGE_TYPE_NEGATIVE.
if (nNeg)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(nHeal), oCreature);
AssignCommand(oCreature, SpeakString("Negative Energy damage healed this creature!"));
// SendMessageToPC(oPC, "Healed: " + IntToString(nHeal));
}
// SendMessageToPC(oPC, "NewHP: " + IntToString(GetCurrentHitPoints()));
ExecuteScript("nw_c2_default6", oCreature);
}