How to remove visual effect

When scripting there is a function called RemoveEffect, but that doesn’t seem to work on Visual Effect. So how do you remove a Visual Effect (in this case VFX_DUR_SPELL_STONESKIN)?

When applying that visual effect, you can speciffy some custom spell id for it and later remove all effects associated with that spell id.

Ex:

void main()
{
	object oTarget = GetControlledCharacter(OBJECT_SELF);
	effect eVis = EffectVisualEffect(VFX_DUR_SPELL_STONESKIN);
	eVis = SetEffectSpellId(eVis, 9999); //9999 <-- just for example here, you can use
                                         //any valid id that doesn't conflict with
                                         //existing ones in spells.2da or in other scripts
	ApplyEffectToObject(DURATION_TYPE_PERMANENT, eVis, oTarget);
}

And then:

void main()
{
	object oTarget = GetControlledCharacter(OBJECT_SELF);

	effect eSearch = GetFirstEffect(oTarget);
	while (GetIsEffectValid(eSearch))
	{
		if(GetEffectSpellId(eSearch) == 9999) //your custom spell id
		{
			RemoveEffect(oTarget, eSearch);
		}
		eSearch = GetNextEffect(oTarget);
	}
}
3 Likes

sidenote: If the effect is a linked effect (more than one effect), RemoveEffect() clears all the effects that are linked - which is what you’d want.

But it can, and i believe will, likely throw the GetFirst/Next-iterator off … so I’ve developed a habit of re-initializing the iterator each time an effect is removed. That is, start from scratch:

    effect eSearch = GetFirstEffect(oTarget);
    while (GetIsEffectValid(eSearch))
    {
        if (GetEffectSpellId(eSearch) == 9999) //your custom spell id
        {
            RemoveEffect(oTarget, eSearch);
            eSearch = GetFirstEffect(oTarget);
        }
        else
            eSearch = GetNextEffect(oTarget);
    }

ref. ‘nw_i0_spells’ RemoveSpellEffects(), RemoveSpecificEffect()

5 Likes

Actually, in this case, you don’t really have to assign a spell ID. To unpetrify your entire party and remove the stoneskin effect caused by EffectVisualEffect (FX_DUR_SPELL_STONESKIN), use this script:

#include "x0_i0_petrify"

void main()
{
	object oPC = GetFirstPC();
	effect eEffect;
	
	object oFM = GetFirstFactionMember(oPC, FALSE);
	while (GetIsObjectValid(oFM))
	{
		Depetrify(oFM);
		eEffect = GetFirstEffect(oFM);
		while (GetIsEffectValid(eEffect))
		{
			if (GetEffectSpellId(eEffect) < 0) RemoveEffect(oFM, eEffect);
			eEffect = GetNextEffect(oFM);
		}

		oFM = GetNextFactionMember(oPC, FALSE);
	}
}
2 Likes

Thanks for the replies you guys!

As you suspected travus I used your script for the petrify and stoneskin (and also a few variations of that script that I made myself for other circumstances), so it looks like the easiest thing to do is just to go by your script here to depetrify (this function I found before, but it only removed the petrifying and not the stoneskin effect) and remove the visual stoneskin effect.

I’m impressed with all of you script wizards, how you know all these things, and above all where to find all these things when scripting. It can be quite daunting to know what function to use or how to get around a problem…but maybe you’re all programmers in real life (which clearly I am not, LOL) and you just know this stuff. :slightly_smiling_face:

1 Like

I took out the Depetrify(oFM); line form Travus’ script, and this now works on any vfx or effect

1 Like

Looking at travus’ script after all these years, I see that you are correct. Good you could find use for it.

1 Like