function rocket_event()
{ if (event_type == EVENT_DETECT) //event runs once for every Entity within range.
{ if((you.skill99>=5)&&(you.healthpoints>0)) //if THIS scan-target(you) is enemy & "alive"
{ //check if target is set yet. "parent" property of ME is the existing target
if(!me.parent) me.parent = you; //no target yet, so set it to THIS
//check if THIS target is closer than the existing closest target
if(vec_dist(me.x, your.x)<vec_dist(me.x, me.parent.x)) me.parent = you;
} }
else if(event_type == EVENT_ENTITY) //rocket hit something
{ me.skill1 = 10; } //explode !!!
}
//
//
action my_rocket()
{ //tweakables
my.skill1 = 1; // below 10 means rocket is alive. Above means the rocket has been exploded.
my.skill2 = 0; // ??? distance
my.skill3 = 500; // "See" Range of the rocket in quants.
my.skill4 = 0; // ??? distance
my.skill5 = 50; // rockets speed in quants-per-second
/////////////////////////////////////////////////////////////////////////////////////
my.emask |= ENABLE_DETECT|ENABLE_ENTITY;
my.event = rocket_event;
while(my.skill1<10)
{ //find nearest living target
my.parent = NULL;
c_scan(my.x, nullvector, vector(360,360,my.skill3), SCAN_ENTS|IGNORE_ME);
//turn towards current target
if(my.parent)
{ vec_set(target, my.parent.x);
vec_to_angle(my.pan, vec_sub(target, my.x));
//OPTIONAL/DEBUGGING :: draw tracer to target
draw_line3d(my.x,0,0); draw_line3d(my.x,vector(0,0,255),50);
draw_line3d(my.parent.x,vector(0,0,255),50);
}
//move towards target
// c_move(me, vector(my.skill5*time_step,0,0), NULL, IGNORE_PASSABLE);
//
wait(1);
}
//target reached
/////////////////////////////////////////////////////////////////////////////////////
// TODO: Sound-effect
// TODO: Damage things. Hit object is pointed to by pointer YOU
// TODO: BUT, if YOU is null, then hit terrain or block at "target.x, .y, .z"
ent_remove(me);
}