Build your own trigger

The spawn functions of triggers in Quake invariably do two things. One is to set appropriate fields on the trigger to make it function – most importantly giving the trigger the right “touch” function, but often setting other keys that function needs (e.g. trigger_monsterjump setting default values for speed and height of jump). The other thing they do is call the InitTrigger function. This function makes the trigger touchable, invisible and the correct size – all the technical stuff a trigger needs.

If we want to create our own trigger with an entity hack, the first half doesn’t bother us. We don’t need a function to set keys on our entity, we can just set the keys for ourselves! However, the InitTrigger bit is something we can’t do without – you can’t simulate the effects of that function by setting keys; it calls built-in engine functions to do the magic.

It turns out there’s a very simple way to run InitTrigger on a hacked entity – simply make InitTrigger the classname of your hacked entity. Then InitTrigger runs as a spawn-function, and as long as you have set all your keys then your trigger is complete. A quick example:

classname: InitTrigger
touch: SUB_UseTargets

This entity will fire its targets when ANYTHING collides with it, from a nail to a monster, or a player. It has no retrigger timer either, it will even fire multiple times per frame if more than one thing touches it. BSP objects never collide with triggers, so they do not count…

classname: InitTrigger
touch: multi_trigger
wait: 2

This is a slightly more sane variant, it still gets triggered by any entity which can collide with it, but it puts a 2 second delay on, and will also play a sound in the noise key. Finally, it lets you specify which entity is the activator by number using the enemy key. One unusual use of this would be in co-op, to wake a bunch of enemies and make them mad at a specific player. In single-player, set enemy: 1 and the player always counts as the person who activated the trigger, regardless of which entity touched it! Again, this mostly matters for waking up enemies and making them angry at the right player (you can’t use this to provoke infighting).

One last example:

classname: InitTrigger
touch: health_touch
healamount: 50
healtype: 2
noise: misc/outwater.wav

This creates a trigger which heals the player by 50 hp when touched. healtype 2 means it’s allowed to overheal the player, and the health will tick back down like a megahealth. You can choose any sound you like in noise, I picked one which is always precached to make it simple.

The examples I’ve shown largely revolve around using an existing touch function in a strange way. You aren’t limited to that though, you can use completely unrelated functions if you like. However, most functions outside of the touch function world won’t interact with the colliding entity in any way, so they’ll be more focused on doing something with the trigger entity. Finding something like SUB_UseTargets, which ignores the colliding entity but affects entities outside the trigger itself is usual more interesting.


6 thoughts on “Build your own trigger

    • Hi Petr,
      Any sound you use needs to be precached by some other entity. If you’re using the sound “misc/outwater.wav” from the post, that should always be precached (in vanilla Quake) so check the spelling.

      If you want a sound which isn’t automatically precached, you have to create an non-hacked entity which will precache it for you. For example if you wanted “misc/secret.wav”, one method is to add a trigger_multiple with “sounds” “1” somewhere in the map.

      It’s impossible to use a sound that isn’t precached by an existing entity, so you can’t get custom sounds, and you can’t e.g. use shambler sounds without including a shambler in the map.

      • Yes, I was using Enforcer’s line (enforcer/sight2.wav) and they’re nowhere on the map.

        After I placed them, it worked.

Leave a Reply to Toggleable trigger_push | The Tome of Preach Cancel reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.