RemoveEffect(object, effect)

Removes an effect from a creature or object.

void RemoveEffect(
    object oCreature,
    effect eEffect
);

Parameters

oCreature

The object to remove an effect from.

eEffect

The effect to remove.


Description

Removes eEffect from oCreature.



Remarks

A common mistake with this function is to use the following approach to remove, say, a sleep effect:

effect eSleep=EffectSleep();
RemoveEffect(oPC, eSleep);

This doesn't work, because calling EffectSleep creates a new effect. It is thus not the sleep effect that is currently on oPC, but a different sleep effect.

Instead, you must loop through effects on the creature, and remove the effect(s) of the correct type, and possibly the correct creator and subtype. View the codesample below for information on how to do this. Alternately, you can use RemoveSpecificEffect which requires you to include nw_i0_spells - it does the same as the code sample below, but is a nice wrapper function to avoid having to type up all that stuff repeatedly.


Version

1.61

Example

void main()
{
object oPC=GetEnteringObject();

if (!GetIsPC(oPC)) return;

//Remove blindness from the PC
effect eLoop=GetFirstEffect(oPC);

while (GetIsEffectValid(eLoop))
   {
   if (GetEffectType(eLoop)==EFFECT_TYPE_BLINDNESS)
         RemoveEffect(oPC, eLoop);

   eLoop=GetNextEffect(oPC);
   }
}

See Also

functions: GetEffectDurationType | GetEffectSpellId | GetEffectSubType | GetEffectType | GetFirstEffect | GetIsEffectValid | GetNextEffect | RemoveEffectOfType | RemoveSpecificEffect
categories: Effects Functions


 author: Tom Cassiotis, editor: Lilac Soul