Well judging by your code you still let them hit the NPC for whatever reason so just do something like...
PHP Code:
public function onNPCHit(itemID, damage, range, attacker, effects, type, pos) {
if (this.dead) return;
this.hp += damage;
showHP();
if (this.hp <= 0) {
this.dead = true;
hide();
sleep(6);
show();
respawn();
}
}
function respawn() {
// your other code
this.dead = false;
}