///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

var walk_percentage;//ignore this vars..they are for future actions
var run_percentage;
var walk_percentage2;
var death_percentage;
var stand_procentaj;
var attack_procentaj;
var front_offset = 30;
var init_offset = 30;
BMAP* crosshair_pcx = "crosshair.pcx";
ENTITY* guard;
ENTITY* bullet;
STRING* bullet_mdl = "bullet.mdl";
function fire_bullets();
function move_bullets();
function remove_bullets();

function main()
{
video_mode = 7;
video_screen = 1;
level_load ("mylvl.wmb");
mouse_mode=1;
mouse_map = crosshair_pcx;
wait (2);
while (1)
{
mouse_pos.x = 400;
mouse_pos.y = 300;
camera.pan -= mouse_force.x;
camera.tilt += mouse_force.y;
wait (1);
}
}


function attach_weapon1()

{
guard = my;
set(my, PASSABLE);
while (1)
{
vec_set (my.x, vector (20, -10, 0));
vec_rotate (my.x, you.pan);
vec_add (my.x, you.x);
my.pan = you.pan;
my.tilt = camera.tilt;
wait (1);
}
}

action players_code()

{
player = my;
ent_create ("guard.mdl", nullvector, attach_weapon1);
while (1)
{
c_move (my, vector(10 * (key_w - key_s) * time_step, 6 * (key_a - key_d) * time_step, 0), nullvector, GLIDE);
vec_set (camera.x, player.x);
camera.z += 45;
camera.pan -= 5 * mouse_force.x * time_step;
camera.tilt += 3 * mouse_force.y * time_step;
my.pan = camera.pan;
set(guard,INVISIBLE);
wait (1);
}
}

function remove_bullets()

{
wait (1);
ent_remove (my);
}

function move_bullets()

{
VECTOR bullet_speed[3];
my.emask = ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK;
my.event = remove_bullets;
my.pan = guard.pan;
my.tilt = guard.tilt;
bullet_speed.x = 35 * time_step;
bullet_speed.y = 0;
bullet_speed.z = 0;
while (my)
{
c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE | IGNORE_YOU);
wait (1);
}
}

VECTOR temp;

ENTITY* bullet;

function fire_bullets()

{
VECTOR bullet_pos;

mouse_spot.x = bmap_width(crosshair_pcx)/2; // hot spot in the bmap center
mouse_spot.z = bmap_height(crosshair_pcx)/2;
vec_to_angle(temp,mouse_dir3d);
vec_for_vertex(bullet_pos, guard, 6);
ent_create("bullet.mdl", bullet_pos, move_bullets);

while(1)
{
VECTOR temp;
temp.x = mouse_pos.x - bmap_width(crosshair_pcx)/2;
temp.y = mouse_pos.y - bmap_height(crosshair_pcx)/2;
temp.z = 5000;
vec_to_screen(temp, camera);
c_trace(guard.x, temp, 0);
vec_set(temp, target.x);
vec_sub(temp, guard.x);
vec_to_angle(guard.pan, temp);
vec_to_angle(guard.pan,mouse_dir3d);
wait(1);

}
}

function bullets_startup()

{
on_mouse_left = fire_bullets;
}

//Still doesen't works! :(( As i set my.pan =temp; it gives me "uncliered indentifier" P.S.:It is just an experimental script,so it may have some mistakes;