//
Code:
/*
blinkSword.wdl
2008.08.15
tD
pseudo-auto generated from src: Blink
incomplete: died of boredom
untested; probably errors
already have similar but more advanced (sword fighting)
	available upon request
	working on model parts right now
*/

var video_mode = 7; // 800x600
var video_depth = 32; // 16 bit mode

var pl_vDist[3]; // moves the player
var ai_nDist; // moves the enemy

define _wpBase, skill12; 			
define _wpTip, skill15; 				
define _hp, skill18;
define _st1, skill21;
define _st2, skill22;
define _anip, skill23;	

		
font standard_font = <ackfont.pcx>, 6, 9; // panel font
/*******************************
images
*******************************/
bmap spark_map = <spkpart.pcx>;			// for spark particles
bmap blood_map = <bloodspray.pcx>; /		/ for blood particles
/*******************************
sounds
*******************************/
sound beep_sound = <msg.wav>;
sound sword_snd = <knife.wav>;

/*******************************
animation strings
*******************************/

var _STAND = 0;
var _WALK = 1;
var _ATK1 = 2;
var _DEAD = 3;
TEXT ani_t1 {
	strings  = 4;
	string = "stand";
	string = "walk";
	string = "attack";
	string = "death";
}

/*******************************
function prototypes
*******************************/
function particle_sparks();
function particle_blood();
function fade_particle();

string lvl_s1 =  "testswordlvl.wmb";	// level string
string hp_s1 = "STRENGTH: ";		// hitpoints string

ENTITY* ai_e1; 	// useful only if you want to display its health

var k_st[512];
var k_ml = 280; 	// mouse left
var k_mr = 281; 
var k_mm = 282; 

panel hp_p1 {  // sux compared to alternatives
	pos_x = 0;
	pos_y = 0;
	digits =120, 575, 4, standard_font, 1, player._hp;
	flags = refresh, visible;
}

text hp_t1 { 	// sux compared to alternatives
	pos_x = 30;
	pos_y = 550;
	font = standard_font;
	string = hp_s1;
	flags = visible;
}


/*******************************
main
*******************************/
function main() {
	level_load (lvl_s1);
	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._hp = 100; // and I have 100 health points

	while (player._hp > 0) { // as long as I'm alive
		// camera
		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
		
		//move
		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
		pl_vDist.x = 10 * ((key_w || cuu) - (key_s || cud)) * time_step; // moves forward / backward with W / S
		pl_vDist.y = 5 * ((key_a || cul) - (key_d || cur)) * time_step; // move side to side
		pl_vDist.z = 0;
		var pl_bWalk; pl_bWalk = (abs(pl_vDist.x) > 0) || (abs(pl_vDist.y) > 0); 
		if (pl_bWalk) { // the player is walking
			my._st1 = _WALK;	// reset ani
			if (my._st1 != my._st2) { my._anip = 0; }
			ent_animate(ani_t1.string[my._st1], my._anip, ANM_CYCLE); // play walk frames animation
			my._anip += 4 * time_step; // "walk" animation speed
			my._anip %= 100;
		} else {  // not walking
			my._st1 = _STAND
			if (my._st1 != my._st2) { my._anip = 0; }	// reset ani
			ent_animate(ani_t1.string[my._st1, my._anip, ANM_CYCLE); // play stand frames animation
			my._anip += 2 * time_step; // "stand" animation speed
			my._anip %= 100;
		}
		ent_move(pl_vDist, nullvector);

		if (mouse_left && k_st[k_mm]) {// if we press the left mouse button
			my._anip = 0; // reset "attack" frames
			while (my._anip < 100) {
				ent_vertex(my._wpTip, 601); // sword tip vertex coords - get the value in Med
				ent_vertex(my._wpBase, 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
				result = trace (my._wpBase, my._wpTip); // trace between these sword positions

				if (result != 0) { // the player has hit something
					effect (particle_sparks, 10, target, normal);
					if (you != null) {you._hp -= 6 * time_step;} // if it hasn't hit a wall, decrease health
					ent_playsound (my, sword_snd, 50); // sword sound
				}
				my._st1 = _ATK1;
				if (my._st1 != my._st2) { my._anip = 0; }	// reset ani
				ent_animate(ani_t1.string[my._st1], my._anip); // play attack frames animation
				my._anip += 17 * time_step; // "attack" animation speed
				my._st2 = my._st1;
				
				wait (1);
			}
			k_st[k_mm] = !mouse_left; // can't use autofire on a sword
		}
		my._st2 = my._st1;
		wait (1);
	}
	my._st1 = _DEAD;
	my._anip = 0;
	while (my._anip < 90) { // the player is dead
		ent_animate(ani_t1.string[my._anip], my._anip); // play death frames animation
		my._anip += 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
	ai_e1 = me; // I'm the enemy

	ai_e1._hp = 20; // and I have 100 _hp

	while (my._hp > 0)  { // as long as I'm alive
		if (vec_dist (my.x, player.x) < 600 && player._hp > 0)  {// the player approaches the enemy
			vec_diff(temp, player.x, my.x);
			vec_to_angle(my.pan, temp);
			my.tilt = 0; // I'm a maniac
			
			ai_nDist.x = 5 * time_step;
			ai_nDist.y = 0;
			ai_nDist.z = 0;
			my._st1 = _WALK;
			if (my._st1 != my._st2) { my._anip = 0; }
			ent_move(ai_nDist, nullvector);
			ent_animate(ani_t1.string[my._st1], my.skill19); // play walk frames animation
			my._anip += 10 * time_step; // "walk" animation speed
			my._anip %= 100;

			if (vec_dist (my.x, player.x) < (my.max_x * 1.10)) { // if the player comes closer than 50 quants attack him 
				my._st1 = _ATK1;
				my._anip = 0; // reset "attack" frames
				while (my._anip < 100){
					ent_vertex(my._wpTip, 2124); // sword tip vertex coords - get the value in Med
					ent_vertex(my._wpBase, 517); // sword base vertex coords - get the value in Med
					trace_mode = ignore_me + ignore_passable;
					result = trace (my._wpBase, my._wpTip); // 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._hp -= 0.5 * time_step;}
						ent_playsound (my, sword_snd, 50); // sword sound
					}
					ent_animate(ani_t.string[my._st1], my._anip); // play attack frames animation
					my._anip += 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
			my._st1 = _STAND;
			if (my._st1 != my._st2) { my._anip = 0; }
			ent_animate(ani_t1.string[my._anip], my._anip, ANM_CYCLE); // play stand frames animation
			my._anip += 2 * time_step; // "stand" animation speed
			my._anip %= 100;
		}
		my._st2 = my._st1;
		wait (1);
	}

	while (my._anip < 80) {// the enemy is dead
		my._st1 = _DEAD
		ent_animate(ani_t1.string[my._st1], my._anip); // play death frames animation
		my._anip += 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;}
}
// 


Quote:
still having difficulty, anyone else have any ideas?

Yes. Instead, just use 'my' scripts which do something similar but more.
(available upon request)