(Quake2) func_timer that starts immediately?

Discuss the construction of maps and the tools to create maps for 3D games.
Post Reply
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

(Quake2) func_timer that starts immediately?

Post by jitspoe »

So I'm trying to figure out a way to do this in vanilla Quake2:

Timer starts playing a sound ~2 seconds after the match start, then repeats every 30 seconds.

The problem is, when start_on is set, it adds the wait time to the initial start, so if I have "delay" set to "2" and "wait" set to "30", it'll be 32 seconds before I hear any sound.

I tried doing something clever and removed the start_on flag and added another func_timer with the start_on flag that targeted the sound. When triggered, only the delay is used. Then I used a trigger_relay to shut the timer off:

func_timer -> func_timer -> target_speaker
^
|
V
trigger_relay

That just caused a stack overflow. :(

Code: Select all

void func_timer_think (edict_t *self)
{
	G_UseTargets (self, self->activator);
	self->nextthink = level.time + self->wait + crandom() * self->random;
}

void func_timer_use (edict_t *self, edict_t *other, edict_t *activator)
{
	self->activator = activator;

	// if on, turn it off
	if (self->nextthink)
	{
		self->nextthink = 0;
		return;
	}

	// turn it on
	if (self->delay)
		self->nextthink = level.time + self->delay;
	else
		func_timer_think (self);
}
If only those 2 lines in func_timer_think were reversed, that would probably work. :(

Any idea how to get the behavior I want without code modifications?
jitspoe
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: (Quake2) func_timer that starts immediately?

Post by jitspoe »

Never mind. I figured out a way. Apparently you can have a trigger_once that has a targetname and a delay, so I was able to:

func_timer->func_timer->target_speaker
^ |
| V
| trigger_relay
| |
| V
\ trigger_once


Edit: Actually, I think the relay is pointless. I can probably just do func_timer<->trigger_once.
Post Reply