Reusable trigger_counter

A trigger_counter is a one-time deal, it activates and then it’s removed. Today we’re going to create a trigger_counter which can be used over and over again.



As with all good hacks, it’s devastatingly simple in concept, and you can see from the picture above where the inspiration is drawn from. Simply create a trigger_multiple with health 45, and aim a spikeshooter at it. Each time you use the spikeshooter you do 9 damage, after 5 spikes the button will activate. *Mic drop*.

Yeah, of course that’s not the end of the article! The basic idea is important though: we use the health of an entity as our counter, because restoring the health of a entity is a built-in feature of trigger_multiple and func_button, so it’s easy to reuse. The first tweak to the setup is to replace the spikeshooter with lightning, so that the reaction time is instant. Position the following entity within your trigger_multiple:

"classname" "info_notnull"
 "use" "W_FireLightning"
 "ammo_cells" "999999999999"

This is player lightning, which does 30 damage per tick. So you need to increase the health of your trigger_multiple accordingly, 30hp times the count desired.

In the basic example, our reusable trigger_counter resets itself after a period of time. It might be nicer to make a trigger which we explicitly reactivate. I spent some time trying to come up with a hacked trigged which:
a) On death fires its targets and goes non-solid/non-damageable
b) On use returns back to normal

All the tricks I tried had some hitch I couldn’t work around. Eventually it struck me that it would be very easy to get the same effect using a logic gate. We need a basic open-closed logic gate which filters the trigger going to the lightning entity. The idea is that to deactivate the counter, we block the lightning from triggering with the gate, so we don’t need to care that the counter has automatically reset! The gate should be hooked up to close when the counter dies and fires its targets. Reactivating the counter is just a matter of opening the gate again.

Would you like to earn the respect of the other readers and my own personal gratitude? If you can figure out how to rig up a trigger which does a) and b) outlined above, without resorting to a logic gate, then post a comment in the box below. You could be the first guest feature on this blog!

The only flaw in this setup is that then after we have re-opened the gate, we also have to wait for the trigger_multiple to reset. We can set the wait arbitrarily low, but we can’t make it instant. Here’s a scenario where that might matter: Imagine we have 20 zombies, and we want a reusable trigger_counter which fires each time 5 more zombies are killed. Also imagine that progression in the map depends on the trigger activating for the 4th time when zombie 20 dies. Our current set-up has a bug when the player kills the last 6 zombies in a single rocket explosion, because the first death will trigger the counter for the 3rd time, then the counter must be inactive for the rest of this frame, and the other 5 deaths will fail to trigger it.

The following hacked entity can be restored immediately via its own use function:

"classname" "InitTrigger"
"max_health" "100"
"target" "output_counter"
"targetname" "reset_counter"
"use" "multi_wait"
"th_die" "SUB_UseTargets"
"think" "multi_wait"
"nextthink" "0.05"

You must make sure to use a logic gate to prevent lightning striking it before you have restored it – before restoration it has negative health, but can still be attacked and will in fact die again to any attack! You can use the same targetname for opening the logic gate and resetting the counter to streamline the operation.

One nice bonus feature of this entity is that you can reset it even when it hasn’t been triggered yet. This instantly resets its health to maximum, so the count must restart from the beginning. You might be able to use this to create new puzzles, e.g require the player to complete several actions in a row correctly, and reset their progress if they make a mistake.


2 thoughts on “Reusable trigger_counter

  1. My own personal gratitude has been withdrawn, as I believe I’ve cracked how to satisfy a) and b) without needing the logic gate. Follow up post coming shortly…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s