if IsEssential if getav health <= 0 player.additem GlassesBlackrimmed 1 ; just a check endifendif
However, checking the health is slightly unreliable. If the actor is killed by the Kill command, for example, it's health doesn't drop and there may be other circumstances where it will fail.
I will probably still use this method, since it's reliable enough, but if anyone has a better suggestion I'd be glad to hear it.
If nothing else there's now a code example on the forum.