Hey folks,

Been trying to adapt a script from a buddy that creates an object, controlls its alpha and removes it from the scene when no longer required to be ready again to recreate.
Most of it is working fine EXCEPT that when the object is assigned its action/function, the functions never stop.

Having worked at this all day I can no longer see straight so if anyone could help me out here I would feel indebted.

Code:
var MKt1 = 1;

function remove_t1();
function tree1();

ENTITY* marker;

#define health skill40


function tree1()
{
	while(player == NULL){wait(1);}
   my.red = 200;
   my.green = 220;
   my.blue = 200;
   set(my, TRANSLUCENT);
   my.alpha = 0;
   set(my, PASSABLE);
   set(my, SHADOW); 
  	my.health = 100; 
    while (1)
    {  
       while (vec_dist(my.x, player.x) > 800){wait(1);}
    	 if ((vec_dist(my.x, player.x) < 800) && (MKt1 ==0))
       {
       	if(my.alpha < 100)
            {
            	my.alpha += 15 * time_step;
            	if(my.alpha > 100)
            	{
            		my.alpha = 100;
					}
				}
		 	}
       	else
       	{
          	my.alpha -= 5 * time_step;	
          	my.health -= 5 * time_step;
          	if((my.alpha < 0)&&(my.health < 0))
            	{
            		my.alpha = 0;
            		my.health = 0;
					}
          }
       
       wait (1);
       remove_t1();
    }
}


function remove_t1()
{
	while(vec_dist(my.x, player.x) < 900){wait(1);}
	if ((vec_dist(my.x, player.x) > 900)&&(MKt1 ==0))
	{ 
      if((my.health)&&(my.alpha))
       {
        	my.health = 0;
       	my.alpha = 0;
       	wait(-1);
       	ent_remove(me);
			MKt1 = 1;
       }
	}
}
action makem()
{
	while(player == NULL){wait(1);}
	marker = me;
   set(my, PASSABLE);
   while(1)
   {
   	if((vec_dist(my.x, player.x) < 800) && (MKt1 == 1))  
				{
					ent_create ("cbabe_unanim.mdl", vector(-3554.000, 39.000, -150.000), tree1);
					MKt1  = 0;
				}
				wait(1);
	}
   
}


The way it is written out now allows the script to work in a basic sense in that the expected behaviour is exhibited successfully but maybe thats why it dont work properly?

Thanks....