In the ongoing effort to tweak this contribution, here's the solution to the negative health numbers:
Add the red text to this function.
Code:
FUNCTION handle_sword_collision
{
you = null;
ent_vertex(my.weapon_tip, 1016); // weapon tip vertex coords - get the value in Med
ent_vertex(my.weapon_base, 1000); // weapon base vertex coords - get the value in Med
if(c_trace (my.weapon_base, my.weapon_tip, ignore_me | ignore_passable)!= 0)&& (you != null)
{
target_enemy.enemy_health -= 5;//*time_step;
if(target_enemy.enemy_health < 100)
{
target_enemy.enemy_health = max(target_enemy.enemy_health,0);
}
IF (airborne_attack == 1 && my.animblend == attack_a) {
my.movement_mode = 2;
}
IF (target_enemy == null)
{
target_enemy = you;
player_lock_on = 1;
}
}
}
In ACTION ENEMY, make this change:
Code:
ACTION enemy
{
my.shadow = on;
my.enemy_health = 100;
my.polygon = off;
my.passable = off;
wait(1);
vec_set(my.min_x, vector(-8,-12,-35)); //get amounts in MED from model
vec_set(my.max_x, vector(23,12,35));
my.narrow = on;
my.fat = on;
my.enable_scan = on;
my.enable_detect = on;
WHILE (1)
{
dying_dead();
IF (my.hit_by_player == 1)
{
my.move_x = player.move_x;
my.move_y = player.move_y;
my.move_z = player.move_z;
c_move(my,nullvector,my.move_x,use_aabb | ignore_passable | glide|use_box);
IF (player.animblend == blend || player.animblend < attack_a || my.animblend > attack_f) { my.hit_by_player = 0; }
}
IF (player.animblend >= stand && target_enemy == my && player_lock_on == 0) && (player.animblend < attack_a || player.animblend > attack_f) { target_enemy = null; }
IF (target_enemy == my && vec_dist(my.x,player.x) > 600) { target_enemy = null; }
wait(1);
while (my.enemy_health > 0) // as long as I'm alive
{
if (vec_dist (my.x, player.x) < 600)&& (player != null) // the player approaches the enemy
{
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;
enemy_distance.x = 5 * time_step;
enemy_distance.y = 0;
enemy_distance.z = 0;
c_move(my,vector(5*time,0,0),my.move_x,use_aabb | ignore_passable | glide|use_box);
ent_animate(my,"walk", my.skill20,anm_cycle); // play walk frames animation
my.skill20 += 5 * time_step; // "walk" animation speed
if (vec_dist (my.x, player.x)< 45)&& (player != null) // if the player comes closer attack him
{
snd_play(club_snd,50,0);
my.skill21 = 0; // reset "attack" frames
while (my.skill21 < 100)&& (player != null)
{
ent_vertex(my.weapon_tip, 1016); // weapon tip vertex coords - get the value in Med
ent_vertex(my.weapon_base, 1000); // weapon base vertex coords - get the value in Med
if (c_trace (my.weapon_base, my.weapon_tip, ignore_me | ignore_passable) != 0)
{
if (you != null)
{ // if the player has hit an entity, decrease its health
player.health -= 2 * time_step;
}
if(player.health < 100){player.health = max(player.health,0);}
}
ent_animate(my,"attack", my.skill21,0); // play attack frames animation
my.skill21 += 2 * time_step; // "attack" animation speed
wait (1);
}
}
}
else // the player is farther away
{
if(player.health < 0)
{
// my.skill21 = 0;
proc_kill(4);
}
ent_animate(my,"stand", my.skill21,anm_cycle); // play stand frames animation
my.skill21 += 2 * time_step; // "stand" animation speed
}
wait (1);
}
}
}
Then add an equal sign to the death anim conditions in both the
FUNCTION handle_animation and the FUNCTION dying_dead
IF (my.health <
= 0)
IF (my.enemy_health <
= 0)