#include "NW_I0_SPELLS"
#include "prc_inc_spells"

void main()
{
    //Declare major variables
    int nDuration = 4;
    object oEO = GetEnteringObject();
    object oTarget = oEO;
    location lTarget = GetLocation(oTarget);
    object oCaster = GetNearestObjectByTag("Flame4");
    effect eSlow = EffectSlow();
    effect eVis = EffectVisualEffect(VFX_IMP_SLOW);
    //Find first target in the size
    oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_SMALL, lTarget);
    //Cycle through the objects in the radius
    while (GetIsObjectValid(oTarget))
    {
        if(!PRCMySavingThrow(SAVING_THROW_REFLEX, oTarget, 28, SAVING_THROW_TYPE_TRAP))
        {
            //Apply slow effect and slow effect
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSlow, oTarget, RoundsToSeconds(nDuration));
        }
        //Get next target in the shape.
        oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_SMALL, lTarget);
    }
DelayCommand(1.5, AssignCommand(oCaster, ActionCastSpellAtObject(SPELL_FIREBALL, oEO, METAMAGIC_ANY, TRUE, 5, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)));
}
