Making a spell cast at an object return to the spellcaster

Making a spell cast at an object return to the spellcaster
This is a script for making a spell cast at an object return to the spellcaster. The target still takes damage, however. Great for making sure spellcasters don't blast every chest in sight. This script is for chests, as it checks to see if the chest is trapped or not, and only fires the spell back if the trap is activated. This is pretty easily edited though to not check for any traps and be more like spell turning.

void main { int trapflag = GetIsTrapped(OBJECT_SELF); int spell = GetLastSpell; int spellflag = GetLastSpellHarmful; object oCaster = GetLastSpellCaster; if ((trapflag == TRUE) && (spellflag == TRUE)) { ActionCastSpellAtObject(spell, oCaster, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE); } }