action dusman()
{
VECTOR temp;
var scan_result[2];
var animation_percent[3];
// wait till player is created!
while(!player){ wait(1); }
c_setminmax(me);
while(1)
{
// scan for player:
move_mode = SCAN_ENTS | IGNORE_PASSABLE;
scan_result[0] = c_scan(my.x, my.pan, vector(150, 0, 1000), move_mode);
// if found one:
if(scan_result[0] > 0 && you == player)
{
// handle animations:
move_mode = SCAN_ENTS | IGNORE_PASSABLE;
scan_result[1] = c_scan(my.x, my.pan, vector(5, 0, 5), move_mode);
if(scan_result[1] > 1)
{
// if near something (I don't really know why you scan again..)
ent_animate(me, "scatt", animation_percent[0], ANM_CYCLE); // hit
animation_percent[0] += 2 * time_step; // DON'T FORGET TO USE "time_step" !!
}
else{
// walk here!!
ent_animate(me, "walk", animation_percent[1], ANM_CYCLE);
animation_percent[1] += 3.13 * time_step;
}
// turn to player:
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
// don't allow to change TILT (looks weird):
my.tilt = 0;
// move to target:
move_mode = IGNORE_PASSABLE | GLIDE;
c_move(me, vector(14 * time_step, 0, 0),nullvector, move_mode);
}
else // if player wasn't found:
{
// play stand animation here:
ent_animate(me, "stand", animation_percent[2], ANM_CYCLE);
animation_percent[2] += 2 * time_step;
}
wait(1);
}
}