There was some weird bracket stuff going on.
I rewrote and cleaned up the code a bit, now you should also be able to use it on many enemies:
Code:


define sword_base = skill12; // using skill12, 13, 14 to store the sword_base coords
define sword_tip = skill15; // using skill15, 16, 17 to store the sword_tip coords
define healthpoints = skill18; // just another name for skill18


action enemy_fight
{
var move_dist[3];
var distance;

my.healthpoints = 100;

c_setminmax(my);
wait(1);

while(plBiped01_entity == null) { wait(1); }

while(my.healthpoints > 0)
{
distance = vec_dist(my.x, plBiped01_entity.x);

if(distance < 200) // the player approaches the enemy
{
vec_set(temp, plBiped01_entity.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;

move_dist.x = 5 * time_step;
move_dist.y = 0;
move_dist.z = 0;
c_move(my,move_dist,nullvector,IGNORE_PASSABLE);

ent_animate(my, "walk", my.skill19, ANM_CYCLE); // play walk frames animation
my.skill19 = cycle(my.skill19+5*time_step,0,101); // "walk" animation speed + loop animation

if(distance < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames

while(my.skill20 < 100)
{
vec_for_vertex(my.sword_base,my,306);
vec_for_vertex(my.sword_tip,my,291);

c_trace(my.sword_base,my.sword_tip,IGNORE_ME|IGNORE_PASSABLE);

if(you)
{
you.healthpoints -= 4 * time_step;
}

ent_animate(my,"attack",my.skill20,ANM_CYCLE); // play attack frames animation
my.skill20 += 5 * time_step; // "attack" animation speed

wait(1);
}

wait(6);
}
}
else // the player is farther than 200 quants away
{
ent_animate(my,"stand",my.skill21,ANM_CYCLE); // play stand frames animation
my.skill21 = cycle(my.skill21+2*time_step,0,101); // "stand" animation speed + loop animation
}

wait(1);
}

// enemy was killed:
while(my.skill22 < 80)
{
ent_animate(me,"death", my.skill22, ANM_CYCLE); // play death frames animation
my.skill22 += 1 * time_step; // "death" animation speed

wait(1);
}

my.passable = on; // the corpse can't be hit by the sword from now on
}



But be aware: This code does not include that the enemy takes damage (reacts to a certain event), thus your weapon code needs to handle this.
I'm not sure how the templates work though.