Yeah, the AI is an important part of the map. The spell immunity would only apply to standard abilities. And yeah, making the spell isn't as easy as I first thought it would.
Anyway, would adding the magic immune classification to the unit work? If not then I'll add the real spell immunity to negate the effects.
As for non-target spells, what if I pick every unit within the playable map, or at least within a certain distance of the caster with the condition of having the selective immunity and add real spell immunity the moment an enemy casts a spell?
If that works, for how long should the spell immunity last? And what when multiple enemies cast a spell? Wouldn't that interfere with allies targeting the unit?
Edit: Actually, I think I found a better way. What if I put spell immunity in a disabled spellbook and every time an enemy unit casts a spell, I add it to the unit and every time an ally casts a spell, I remove the spellbook? Would that work?