ok...i was working on converting/combining two a5 scripts to a6 that were contributions from another site. i was able to get it running with no errors, but my dilemma is, when the main character approaches the enemy model, the enemy turns away, and then follows the player model around. i dont understand what's wrong. i am no coder, so can one of the great code masters please look at this and tell me whats wrong? i would like to contribute this to the community so us coding noobs can have a easy a.i. to play with.

Code:
//sword/////
////////////////////////////////////////////////////////////

 

var video_mode = 7; // 800x600

var video_depth = 32; // 16 bit mode

 

var player_distance; // moves the player

var enemy_distance; // moves the enemy

 

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

font standard_font = <ackfont.pcx>, 6, 9; // panel font



//////////////////////////////////////////////////////////////

 

bmap spark_map = <spkpart.pcx>;// for spark particles

bmap blood_map = <bloodspray.pcx>; // for blood particles

 

//////////////////////////////////////////////////////////////

 

sound beep_sound = msg.wav;

sound sword_snd = knife.wav;

 

//////////////////////////////////////////////////////////////

 

function particle_sparks();

function particle_blood();

function fade_particle();

 

//////////////////////////////////////////////////////////////

 

string sword_combat_wmb =  testswordlvl.wmb ;

string health_str = "STRENGTH: ";

 

///////////////////////////////////////////////////////////////

 

entity* enemy; // useful only if you want to display its health

 

///////////////////////////////////////////////////////////////

 

panel health_panel // displays the numbers

{

pos_x = 0;

pos_y = 0;

digits =120, 575, 4, standard_font, 1, player.healthpoints;

flags = refresh, visible;

}

text health_text // displays the text

{

pos_x = 30;

pos_y = 550;

font = standard_font;

string = health_str;

flags = visible;

}

 

////////////////////////////////////////////////////////////////

 

function main()

{

level_load (sword_combat_wmb);

wait (2); // wait for the level to be loaded

clip_size = 0; // show all the triangles for all the models

on_d = null; // disable the debug panel (key "D") because it is used for movement

fps_max = 40; // lock the frame rate to 40 fps

}

 

action player_fight // attached to the player

{

player = me; // I'm the player

player.healthpoints = 100; // and I have 100 health points

while (player.healthpoints > 0) // as long as I'm alive

{

camera.x = player.x - 200 * cos(player.pan); // 200 = distance between the player and the camera

camera.y = player.y - 200 * sin(player.pan); // same value here

camera.z = player.z + 50; // above the player

camera.pan = player.pan; // looks in the same direction with the player

camera.tilt = -10; // look down at the player

 

my.pan +=0 * (key_a - key_d) * time_step - 20 * mouse_force.x * time_step; // rotates with the keys A and D or with the mouse

 

 

 

player_distance.x = 10 * (key_w - key_s) * time_step; // moves forward / backward with W / S

 

player_distance.y = 5 * (key_a - key_d) * time_step; // move side to side

player_distance.z = 0;

 

if ((key_w == 1) || (key_s == 1)) || ((key_a == 1) || (key_d == 1)) // the player is walking

{

ent_animate("walk", my.skill20); // play walk frames animation

my.skill20 += 4 * time_step; // "walk" animation speed

if (my.skill20 > 100) {my.skill20 = 0;} // loop animation

}

 

else // the player is standing

{

ent_animate("stand", my.skill21); // play stand frames animation

my.skill21 += 2 * time_step; // "stand" animation speed

if (my.skill21 > 100) {my.skill21 = 0;} // loop animation

}

 

ent_move(player_distance, nullvector);

 

if (mouse_left == 1)// if we press the left mouse button

{

my.skill22 = 0; // reset "attack" frames

while (my.skill22 < 100)

{

ent_vertex(my.sword_tip, 601); // sword tip vertex coords - get the value in Med

ent_vertex(my.sword_base, 5); // sword base vertex coords - get the value in Med

trace_mode = ignore_me + ignore_passable; // ignore me (the player) and all the entities that are passable

trace (my.sword_base, my.sword_tip); // trace between these sword positions

if (result != 0) // the player has hit something

{

effect (particle_sparks, 10, target, normal);

if (you != null) {you.healthpoints -= 6 * time_step;} // if it hasn't hit a wall, decrease health

ent_playsound (my, sword_snd, 50); // sword sound

}

ent_animate("attack", my.skill22); // play attack frames animation

my.skill22 += 17 * time_step; // "attack" animation speed

wait (1);

}

while (mouse_left == 1) {wait (1);} // can't use autofire on a sword

}

wait (1);

}

while (my.skill23 < 90) // the player is dead

{

ent_animate("death", my.skill23); // play death frames animation

my.skill23 += 3 * time_step; // "death" animation speed

wait (1);

}

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

}

 

action enemy_fight // attached to the enemy

{

enemy = me; // I'm the enemy

enemy.healthpoints = 20; // and I have 100 healthpoints

while (my.healthpoints > 0) // as long as I'm alive

{

if (vec_dist (my.x, player.x) < 600 && player.healthpoints > 0) // the player approaches the enemy

{

vec_set(temp, player.x);

vec_sub(temp, my.x);

vec_to_angle(my.pan, temp);

my.tilt = 0; // I'm a maniac

enemy_distance.x = 5 * time_step;

enemy_distance.y = 0;

enemy_distance.z = 0;

ent_move(enemy_distance, nullvector);

ent_animate("walk", my.skill19); // play walk frames animation

my.skill19 += 10 * time_step; // "walk" animation speed

if (my.skill19 > 100) {my.skill19 = 0;} // loop animation

if (vec_dist (my.x, player.x) < 50) // if the player comes closer than 50 quants attack him

{

my.skill20 = 0; // reset "attack" frames

while (my.skill20 < 100)

{

ent_vertex(my.sword_tip, 2124); // sword tip vertex coords - get the value in Med

ent_vertex(my.sword_base, 517); // sword base vertex coords - get the value in Med

trace_mode = ignore_me + ignore_passable;

trace (my.sword_base, my.sword_tip); // trace between these sword positions

if (result != 0) // hit something, could be the player or another enemy

{

effect (particle_blood, 2, target, normal);

if (you != null) {you.healthpoints -= 0.5 * time_step;}

ent_playsound (my, sword_snd, 50); // sword sound

}

ent_animate("attack", my.skill20); // play attack frames animation

my.skill20 += 5 * time_step; // "attack" animation speed

wait (1);

}

wait (-6); // slows down the enemy and reduces the number of traces per second

}

}

else // the player is farther than 200 quants away

{

ent_animate("stand", my.skill21); // play stand frames animation

my.skill21 += 2 * time_step; // "stand" animation speed

if (my.skill21 > 100) {my.skill21 = 0;} // loop animation

}

wait (1);

}

while (my.skill22 < 80) // the enemy is dead

{

ent_animate("death", my.skill22); // 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

}

 

 

 

function particle_sparks()

{

temp.x = random(2) - 1;

temp.y = random(2) - 1;

temp.z = random(1) - 1.5;

vec_add (my.vel_x, temp);

my.alpha = 30 + random(50);

my.bmap = spark_map;

my.size = 5;

my.flare = on;

my.bright = on;

my.move = on;

my.lifespan = 20;

my.function = fade_particle;

my.gravity =0;

my.beam = on;

my.streak = on;

 

}

 

 

function particle_blood()

{

temp.x = random(2) - 1;

temp.y = random(2) - 1;

temp.z = random(1) - 1.5;

vec_add (my.vel_x, temp);

my.alpha = 70 + random(30);

my.bmap = blood_map;

my.size = 6;

my.flare = on;

my.bright = on;

my.move = on;

my.lifespan = 20;

my.function = fade_particle;

}

 

function fade_particle()

{

my.alpha -= 5 * time_step;

if (my.alpha < 0) {my.lifespan = 0;}

}
 



Thanks in advance, Blink.

Last edited by Blink; 08/01/08 15:28. Reason: stupid me, i forgot the code,lol..

My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."