Don't know if there's even an internal way of tracking it, but what if teleport's AP cost and success rate was made to scale based on factors, like let's say relative level of the target vs the level of the caster/caster's magic stats, or vs weight of the target vs caster's relevant magic stats? Besides that, the easiest solution is simply making certain things immune to teleporting, but that's kind of a heavy handed choice in many cases.