==
maybe grab the id of the mob that is closest to you---since it'd have to be in range of you to physically hit you (barring any zradius flukes where mobs can magically hit you a floor above/below etc)
start with a...
/varset nmob ${Me.NearestSpawn[npc radius #].ID}
then
/target ${nmob}
for when you get hit...replace the # with a a low number, 10-20 range?
that's where I'd start at least...