#define reldist_x skill1
#define reldist_y skill2
#define reldist_z skill3
#define absdist_x skill4
#define absdist_y skill5
#define absdist_z skill6
#define entity_handle skill7
action grenade()
{
my.reldist_x = 16; // forward velocity
my.reldist_y = 0;
my.reldist_z = 0;
my.absdist_x = 0;
my.absdist_y = 0;
my.absdist_z = 16; // the grenade flies upwards at first.
while( my ) // while I exist
{
if( !is(my,FLAG1) ) // "flying through the air" mode
{
my.absdist_z -= time_step; // the grenade flies downward over time.
c_move( my, my.reldist_x, my.absdist_x, USE_POLYGON );
if( trace_hit && you ) // hit an entity
{
// remember the entity I hit with a handle
my.entity_handle = handle( you );
// go to "sticky" mode
set( my, FLAG1 );
}
}
else // "sticky" mode
{
your = ptr_for_handle( my.entity_handle );
if( your ) // only do this if the entity still exists, of course (otherwise we get a pointer error)
{
// In sticky mode, I repurpose my.absdist to be the position of the grenade + the distance between the grenade and the hit entity.
vec_diff( my.absdist_x, my.x, your.x );
vec_add( my.absdist_x, my.x );
vec_set( my.x, my.absdist_x );
}
}
wait(1);
}
}