Code:
//********start of gravity******\\
function gravity
{
var tempgravar; //used instead of the temp var
vec_set(tempgravar,my.x);
tempgravar.z -= 10000; // calculate a position 4000 quants below the player
// set a trace mode for using the player's hull, and detecting map entities and level surfaces only
trace_mode = ignore_me+ignore_sprites+IGNORE_MODELS+USE_BOX;
result = trace(my.x,tempgravar); // subtract vertical distance to ground

if (result > 5) // in the air?
{
force.x = 0; // no pushing force
force.y = 0;
force.z = -10; // gravity force
move_friction = 0.1; // air friction
}
else // on or near ground
{
force.x = my.speed; // translation force
force.y = 0;
force.z = -1 * result; // ground elasticity
move_friction = 0.7; // ground friction
}
my.ahead_speed = time_step*force.x + max(1-time_step*friction,0)*my.ahead_speed; // calculate ahead speed
my.vertical_speed = time_step*force.z + max(1-time_step*friction,0)*my.vertical_speed; // calculate vertical speed
dist.x = 0; //time_step * my.ahead_speed; // distance ahead
dist.y = 0;
dist.z = time_step * my.vertical_speed; // distance down
move_mode = ignore_passable + glide;
ent_move(dist,nullvector); // move the player
}
//**********end of gravity******\\

function special_damage //used to handle magic attacks and other detected entities
{
if(event_type == event_scan && my.health >0)
{
if(you.id == 10)
{
my.health -= 2.5;
}
}
}

function check_event
{
if(event_type == event_scan && my.health > 0)
{
gravity();
special_damage();

if(you.id < 4 && you.id >0) //detection of anything that is a guardian, sprite or user
{
wait(1);
entity_scanning_me = you; //detects who ever scans the skell

if(closest_scanning_entity == 0) // when there is no closest entity then whoever scans me is closest
{
closest_scanning_entity = entity_scanning_me;
}
you = closest_scanning_entity;

if(vec_dist (my.x, you.x) <= my.detection_range && vec_dist (my.x, you.x) > my.attack_range && you.id < 4 && my.state == waiting_state)
{//when something is detected and all the above conditions are true walk up to the closest entity
my.state = walking_state;

while(my.state == walking_state)
{
var varyoux[3]; // At the end of this the you.x will change. This keeps the current you.x
if(you != 0)
{
varyoux.x = you.x;
varyoux.y = you.y;
varyoux.z = you.z;
}
wait(1);
vec_set(temp, varyoux);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp); //face the enamy
my.tilt = 0;
ent_move(my.speed, nullvector);
ent_animate("walk", my.animation); // play walk frames animation
my.animation += my.speed; // animation forwrd / backward
my.animation %= 100;
if (my.animation > 100)
{
my.animation = 0; // loop animation
}
trace_mode = ignore_me+ignore_sprites+USE_BOX;
result = trace(my.x,you.x); //this trace is used so the skell can't see through walls

if(vec_dist (my.x, varyoux) > my.attack_range)
{
my.state = waiting_state; //my state is no longer walking_state
}
}
}

if(vec_dist (my.x, you.x) < my.detection_range && vec_dist (my.x, you.x) <= my.attack_range && you.id < 4 && my.state != attacking_state)
{//if all the above conditions are true attack the closest entity

my.state = attacking_state;
my.animation = 0;
while (my.state == attacking_state)
{
wait(1);
//attack start-----------------------------------------------------------------
if(you != 0)
{
varyoux.x = you.x;
varyoux.y = you.y;
varyoux.z = you.z;
}
vec_set(temp, you.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;

while (my.animation < 100)
{
wait (1);
ent_vertex(my.weapon_tip, 291); // sword tip vertex coords - get the value in Med
ent_vertex(my.weapon_base, 306); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable;
trace (my.weapon_base, my.weapon_tip); // trace between these sword positions
if (result != 0) // hit something
{
if (you != null)
{
you.health -= 1 * time_step;
}
}
ent_animate("attack", my.animation); // play attack frames animation
my.animation += my.speed; // "attack" animation speed
}

if(my.animation >= 100)
{
// wait (1);
my.animation = 0; // reset "attack" frames
}

wait (6); // slows down the skell and reduces the number of traces per second
//attack end-------------------------------------------------------------------
if(vec_dist (my.x, you.x) > my.attack_range)
{
my.state = waiting_state; //my state is no longer attacking_state
}
}
}
return;
}
}
else
{
my.state == waiting_state;
return;
}
}

action skell
{
my.id = 7;
my.health = 100;
my.speed = 4;
my.transparent = on;
my.alpha = 100;

my.detection_range = 500;
my.attack_range = 55;

my.enable_scan = on;
my.enable_detect = on;

my.enable_impact = on;
my.enable_entity = on;
my.event = check_event;
my.state = waiting_state;

while(my.health > 0)
{
wait (1);
temp.x = 360;
temp.y = 0;
temp.z = my.detection_range;
scan_entity(my.x,temp);

while(my.alpha > 10)
{
wait(1);
my.alpha = my.health;
}

if (my.health <= 0) // the skell is dead
{
my.passable = on; // the corpse can't be hit by the sword from now on
my.enable_scan = on;
my.enable_detect = on;
my.enable_impact = on;
my.enable_entity = on;
my.id = 0;
if(vec_dist (my.x, player.x) < 1000)
{
player.experience += 50;
}

my.animation = 0;
while(my.animation < 90)
{
wait (1);
ent_animate("death", my.animation); // play death frames animation
my.animation += 1; // "death" animation speed
my.alpha -= 2;
}
ent_remove(me);
return;
}
}
}

action corps
{
my.passable = off;
my.frame = 34;
}

action virull
{
my.id = 3;
my.health = 50;
my.detection_range = 750;
my.attack_range = 100;
my.speed = 5;
my.transparent = on;
my.alpha = 100;
my.enable_scan = on; // the skell is sensitive to scanning
my.enable_detect = on;
my.enable_impact = on;
my.enable_entity = on;
my.event = check_event;
my.state = waiting_state;

while(my.health > 0)
{
wait(1);
randomize();
my.alpha = random(100);

var float;
randomize();
float = random(2)+15;

if(my.state == waiting_state)
{
//
wait(1);
my.z += my.speed;

if(my.z < 100)
{
while(float > 0)
{
wait(1);
my.z += my.speed;
float -= 1;
randomize();
my.alpha = random(100);
}
}

if(my.z > 150)
{
while(float > 0)
{
wait(1);
my.z -= my.speed;
float -= 1;
randomize();
my.alpha = random(100);
}
}
}

temp.x = 360;
temp.y = 0;
temp.z = my.attack_range;
scan_entity(my.x,temp);

my.tilt -= you.tilt;
my.pan -= you.pan;

if(you.id == 2)
{
ent_create(virull_mdl,you.x,virull);
you.health = 0;
}

}
while(my.health <= 0)
{
my.passable = on;
my.id = 0;
my.enable_scan = off; // the skell is sensitive to scanning
my.enable_detect = off;
my.enable_impact = off;
my.enable_entity = off;

my.alpha = 50 + random(50);

var tilt_or_pan_death;
tilt_or_pan_death = random(2);

if(tilt_or_pan_death > 1)
{
my.tilt = random(100);
}
else
{
my.pan = random(100);
}

while(my.alpha > 1)
{
my.z -= 2;
wait(1);
my.alpha -= 1;
if(tilt_or_pan_death>1)
{
my.tilt += 20+random(5);
}
else
{
my.pan += 20+random(5);
}
}
my.alpha = 0;
ent_remove(me);
return;
}

}

function create_virull
{
ent_create(virull_mdl,player.x,virull);
}

// on_t = create_virull;