Page 1 of 1

Stop a thread

Posted: Wed Dec 03, 2003 7:43 am
by Vic Marrow
Is it possible to stop a thread while it is running? Here's part of my script.
If I set the gards alertness to normal settings the second I shoot Hitler (while all three are walking) they attack me. When I set their alertness to 1 and I shoot Hitler the gards will keep walking even when Hitler is dead, so when they get to the waypoint they spin around and around. (because their .destination is Hitler's destination) How could I get them to stop or go idle or attack etc. the second Hitler is killed.

Code: Select all

	$gard1.smokinginitialized = "no"
	$gard2.smokinginitialized = "no"
	$hitler.smokinginitialized = "no"
	

	$gard1 turnto $g1wp1
	$gard2 turnto $g2wp1
	$gard1 anim atease
	$gard2 anim atease
wait .5
	$gard1 animscript "anim/continue_last_anim.scr"
	$gard2 animscript "anim/continue_last_anim.scr"



	wait 10
	$gard1 thread gard_follow $hitler
	$gard2 thread gard_follow $hitler

	$hitler turnto $wp1 
         while(vector_length ($hitler.origin - $wp1.origin) > 64) 
        { 
        $hitler anim "unarmed_walk_forward"
        $hitler waittill flaggedanimdone 
        } 

	$hitler anim idle
	$hitler.smokinginitialized = "no"


	wait 2

	$gard1 turnto NULL
	$gard2 turnto NULL
	$gard1 anim atease
	$gard2 anim atease

	
wait .5
	$gard1 animscript "anim/continue_last_anim.scr"
	$gard2 animscript "anim/continue_last_anim.scr"


wait 20

	$gard1 walkto $g1wp1a
	$gard1 waittill movedone
	$gard1 turnto $g1wp2
	$gard1 anim atease
	$gard2 walkto $g2wp1a
	$gard2 waittill movedone
	$gard2 turnto $g2wp2

wait .5
	
	$gard1 turnto NULL
	$gard2 turnto NULL

	$gard1 thread gard_follow $hitler
	$gard2 thread gard_follow $hitler
	$hitler turnto $wp2 
         while(vector_length ($hitler.origin - $wp2.origin) > 64) 
        { 
        $hitler anim "unarmed_walk_forward"
        $hitler waittill flaggedanimdone 
        } 

	$hitler anim idle
	$hitler.smokinginitialized = "no"


wait 2
	$gard1 anim atease
	$gard2 anim atease

	
wait .5
	$gard1 animscript "anim/continue_last_anim.scr"
	$gard2 animscript "anim/continue_last_anim.scr"

	$gard1 turnto $east
	$gard2 turnto $east

wait 10

	if(isalive $hitler)
	{
	$gard1 aimat $hitler
	wait 2
	$gard1 fire 
wait .1
	$gard1 fire
wait .1
	$gard1 fire
wait .1
                $gard1 fire
wait .1	
	$gard1 fire
	$hitler killed
wait 3
	$gard1 aimat NULL
	$gard1 turnto $wp2
	$gard1 walkto $wp2
	$gard1 waittill movedone
	$gard1 anim grenade_kick
	}

	else
	{
	$gard1 anim specialmove
	}
end



gard_follow local.hitler:

println "hitler thread active " 

self.destination = local.hitler
self.distance = 3 
self.waittime=1 
self.friendrange = 3
self.runanimrate=1.28

if(isalive local.hitler)
{
	self thread follow_player local.hitler
}

end 


follow_player local.followed: 

      self.destination = local.followed
      self.movedoneradius = self.distance 
          
      if (vector_length (self.destination.origin - self.origin) > self.distance + self.friendrange) 
      
       {
         self animscript "anim/walk.scr" self.destination.origin 

        }

	
end 

Posted: Wed Dec 03, 2003 7:47 am
by jv_map
I didn't read through the whole script you posted, but could you specify which thread you want to stop at which time?

Posted: Wed Dec 03, 2003 2:39 pm
by Vic Marrow
Sorry about that!!!!! This one:

Code: Select all

follow_player local.followed: 

      self.destination = local.followed 
      self.movedoneradius = self.distance 
          
      if (vector_length (self.destination.origin - self.origin) > self.distance + self.friendrange) 
      
       { 
         self animscript "anim/walk.scr" self.destination.origin 

        } 

    
end
While all three ai are walking and I kill Hitler I want the gards to stop walking and change their animation.

Posted: Wed Dec 03, 2003 3:23 pm
by jv_map
I guess this will work:

Code: Select all

follow_player local.followed:
	self.destination = local.followed
	self.movedoneradius = self.distance
         
	if (vector_length (self.destination.origin - self.origin) > self.distance + self.friendrange)
	{
		self animscript "anim/walk.scr" self.destination.origin
		
		local.followed waittill death
		self animscript "anim/idle.scr"
	}
end
Not really a sweet example of stopping a thread, more one of changing the animscript :wink:

Posted: Wed Dec 03, 2003 4:03 pm
by Vic Marrow
Yes!!!!!!!! this worked. This what I was looking for. Awesome!!!!!!!! I tried for like a week to do this by using if (isalive) type statements. I guess I got to ask the fourm sooner. Thanks jv_map Awesome!!!!!!! :D

Posted: Wed Dec 03, 2003 4:34 pm
by jv_map
You're welcome :D
I guess I got to ask the fourm sooner.
Trying things out yourself makes you learn fastest ;), though ofcourse post here when you're stuck :idea:.