EffectSpellFailure(int, int)

From NWN Lexicon
Jump to navigationJump to search

Creates an effect that inhibits spells.

effect EffectSpellFailure(
    int nPercent = 100,
    int nSpellSchool = SPELL_SCHOOL_GENERAL


Percent chance of spell failing (1 to 100). (Default: 100)
Spell school that is affected (SPELL_SCHOOL_*). (Default: SPELL_SCHOOL_GENERAL )


Returns an effect that has a chance of causing a spell to fail. Spells that are cast and fail are lost. Specific schools of spells may be affected (SPELL_SCHOOL_*) or all schools may be affected (SPELL_SCHOOL_GENERAL). To guarantee that no spell can be successfully cast in an area with this effect, apply the effect with its default parameters.

The target this effect is applied to must be a creature for it to work. This effect should not be applied instantly, only temporarily or permanently.

EffectSpellFailure only affects spells cast with the UserType column set to 1. It is not arcane spell failure, it applies to any spell cast.

Note: It currently has a subtype of "0" instead of magical by default.


This effect has nothing to do with arcane spell failure you can put on items (or is naturally there via. armor). It is a separate check, and affects the caster whenever they cast a spell in addition to normal armor checks, concentration checks and so forth. For information on arcane spell failure item property see ItemPropertyArcaneSpellFailure.

It affects spells.2da lines which are UserType "1". It only affects ActionCastSpell (normal spellbook or spells added as monster abilities in the toolset), not using items such as scrolls, potions or wands with that spell. You get the simple message "Spell failed!" with no further feedback (on the roll, or type of failure) when it causes a spell to fail. The casting attempted is lost.

Putting it to 100 will stop any spell being cast. Even 1% can be deadly to a caster. This can be used to create a "magic dead-zone" as per the Time of Troubles (TSR modules FR1 through FR3) although the Spell Hook would needed to stop any items being used.

Effect Breakdown

This effect now properly calculates stacking of this effect in NWN:EE and if one is removed or added it is recalculated properly.

EffectDeaf also adds spell failure specially - it applies 20% if the amount of spell failure is less than 20%.

The percentage is also capped at 0 - 100 even if a higher number is put in.

As noted above the roll is only done on spell castings, not item usage, and only affects spells with a UserType value of 1 (so a dragons breath, or a gaze, is unaffected, but Ray of Frost is, whether in a monsters abilities list or a proper spell book).

As noted in Known Bugs the subtype is not set so it isn't removed by resting. It can be correctly removed if the subtype is set, or you manually remove it with RemoveEffect.

nIndex Parameter Value Description and Notes
0 nPercent The percentage of spell failure, although see effect breakdown for bugs and limits.
1 nSpellSchool The default value - SPELL_SCHOOL_GENERAL - is 0 so may not be apparent.

Known Bugs

Unlike other effects, the subtype of this effect is not magical by default but "none". This can be a problem as such effect will not be removed after resting. To workaround this issue, use MagicalEffect(EffectSpellFailure()); if you want to create a spell failure effect of the magical subtype. Note: This bug may not be fixed due to assumptions in some scripts that assume it is not magical.


This function was updated in 1.87.8193.35 of NWN:EE. Fixed the calculation of stacking spell failure.


// Apply 100% spell failure to anyone who enters this area, after all magical effects are removed!
// NB: In NWN:EE using a tagged effect for this would be recommended
void main()
    // Declare effects
    effect eVis = EffectVisualEffect(VFX_IMP_BREACH);
    effect eDur = EffectVisualEffect(VFX_DUR_GLOW_LIGHT_BLUE);
    effect eAntiMag = EffectSpellFailure(100);
    eAntiMag = EffectLinkEffects(eDur, eAntiMag);
    eAntiMag = SupernaturalEffect(eAntiMag);
    // Get who to effect
    object oTarget = GetEnteringObject();

    // Must NOT be a DM or plot-flagged creature
    if(GetIsDM(oTarget) || GetPlotFlag(oTarget)) return;

    // Remove effects which are magical
    effect eCheck = GetFirstEffect(oTarget);
        if (GetEffectSubType(eCheck) == SUBTYPE_MAGICAL)
            if (GetEffectType(eCheck) != EFFECT_TYPE_DISAPPEARAPPEAR
              && GetEffectType(eCheck) != EFFECT_TYPE_SPELL_FAILURE)
                RemoveEffect(oTarget, eCheck);
        eCheck = GetNextEffect(oTarget);
    // Apply effects
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eAntiMag, oTarget);

// Remove any spell failure when they exit the area
// NB: In NWN:EE using a tagged effect for this would be recommended
void main()
    // Remove from exiter.
    object oTarget = GetExitingObject();
    // Remove effects which are spell failure
    effect eCheck = GetFirstEffect(oTarget);
        if(GetEffectSubType(eCheck) == SUBTYPE_SUPERNATURAL)
            if(GetEffectType(eCheck) == EFFECT_TYPE_SPELL_FAILURE)
                RemoveEffect(oTarget, eCheck);
        eCheck = GetNextEffect(oTarget);

See Also




SPELL_SCHOOL_* Constants

 author: Charles Feduke, editors: Jasperre, Mistress, additional contributors: Jasperre