EffectSpellFailure(int, int)

Creates an effect that inhibits spells.

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

Parameters

nPercent

Percent chance of spell failing (0 to 100). (Default: 100)

nSpellSchool

Spell school that is affected (SPELL_SCHOOL_*). (Default: SPELL_SCHOOL_GENERAL)


Description

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 gurantee that no spell can be successfully cast in an area with this effect, apply the effect with its default parameters.



Remarks

This can be used to create a "magic dead-zone" as per the Time of Troubles (TSR modules FR1 through FR3).


Version

1.30

Example

// Apply 100% spell failure to anyone who enters this area, after all magical effects are removed!
void main()
{
    // Declare effects
    effect eVis = EffectVisualEffect(VFX_IMP_BREACH);
    effect eDur = EffectVisualEffect(VFX_DUR_GLOW_LIGHT_BLUE);
    effect eAntiMag = EffectSpellFailure(100);
    eAntiMag = SupernaturalEffect(eAntiMag);
    eAntiMag = EffectLinkEffects(eDur, 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);
    while(GetIsEffectValid(eCheck))
    {
        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
void main()
{
    // Remove from exiter.
    object oTarget = GetExitingObject();
    // Remove effects which are spell failure
    effect eCheck = GetFirstEffect(oTarget);
    while(GetIsEffectValid(eCheck))
    {
        if(GetEffectSubType(eCheck) == SUBTYPE_SUPERNATURAL)
        {
            if(GetEffectType(eCheck) == EFFECT_TYPE_SPELL_FAILURE)
            {
                RemoveEffect(oTarget, eCheck);
            }
        }
        eCheck = GetNextEffect(oTarget);
    }
}

See Also

categories: Effects Functions
constants: SPELL_SCHOOL_* Constants


 author: Charles Feduke, editor: Jasperre
 Send comments on this topic.