setTimer destroy?

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

setTimer destroy?

Post by Moustache » November 5th, 2011, 2:30 pm

Is it possible to destroy / stop a timer?

I have made the script below. But I want that if the player re spawns the timer gets stopped/deleted/hidden. Now the timer just continues till the end no matter what I try.
Below this script are a few things I have tried.

Script:

Code: Select all

healthBoost()
{
        self notify( "health_boost" );
        self endon( "health_boost" );
        self endon( "disconnect" );
 
        self.maxhealth = 45;
        self.health = self.maxhealth;
        self.health_boost_time = level.health_boost_time;
 
        if( isDefined( self.health_boost_count ))
                self.health_boost destroy();
        if( isDefined( self.health_boost_count ))
                self.health_boost destroy();
        
        wait 0.05;
        
        self.health_boost = newClientHudElem( self );
        self.health_boost.x = 120;
        self.health_boost.y = 10;
        self.health_boost.horzAlign = "left";
        self.health_boost.vertAlign = "top";
        self.health_boost.alignX = "left";
        self.health_boost.alignY = "top";
        self.health_boost.alpha = 1;
        self.health_boost.fontScale = 2;
        self.health_boost.hidewheninmenu = true;
        self.health_boost.color = ( .99, .99, .99 );
        self.health_boost.label = ( &"Health Boost" );
 
        self.health_boost_count = newClientHudElem( self );
        self.health_boost_count.x = 120;
        self.health_boost_count.y = 30;
        self.health_boost_count.horzAlign = "left";
        self.health_boost_count.vertAlign = "top";
        self.health_boost_count.alignX = "left";
        self.health_boost_count.alignY = "top";
        self.health_boost_count.alpha = 1;
        self.health_boost_count.fontScale = 2;
        self.health_boost_count.hidewheninmenu = true;
        self.health_boost_count.color = ( .99, .99, .99 );
 
        self.health_boost_count setTimer( self.health_boost_time );
        wait self.health_boost_time;
 
        self.maxhealth = 30;
        self.health = self.maxhealth;
        
        if( isDefined( self.health_boost ))
                self.health_boost destroy();
        if( isDefined( self.health_boost_count ))
                self.health_boost_count destroy();
}

Code: Select all

onPlayerSpawn()
{
        self iPrintLnBold( "Spawn" ); // This message is visible so the thread gets called
 
// None of the things below can hide the timer or make it stop
        self.health_boost_count.hidden = true;
        self.health_boost_count.alpha = 0;
        self.health_boost_time = 0; // it also doesn't work when I try: self.health_boost_time = undefined;
        self.health_boost_count setTimer( self.health_boost_time  );
        self.health_boost_count destroy();
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: setTimer destroy?

Post by Drofder2004 » November 5th, 2011, 3:08 pm

Firstly, you need to end the wait inside the first code.

self endon ( "death" );
self endon("joined_spectators");

Those will kill the threads when the player dies or goes spec.
Then you should be able to simply "destroy();" them.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: setTimer destroy?

Post by Moustache » November 5th, 2011, 3:18 pm

Drofder2004 wrote:Firstly, you need to end the wait inside the first code.

self endon ( "death" );
self endon("joined_spectators");

Those will kill the threads when the player dies or goes spec.
Then you should be able to simply "destroy();" them.
Thank you for the fast response.
It worked :D

EDIT:
I am so retarded.
I had this in my spawn thread:

Code: Select all

	if( isDefined( self.health_boost_count ))
		self.health_boost destroy();
	if( isDefined( self.health_boost_count ))
		self.health_boost destroy();
No wonder it failed :roll:

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: setTimer destroy?

Post by Drofder2004 » November 5th, 2011, 3:54 pm

Moustache wrote:

Code: Select all

	if( isDefined( self.health_boost_count ))
		self.health_boost destroy();
	if( isDefined( self.health_boost_count ))
		self.health_boost destroy();
No wonder it failed :roll:
:D
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests