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:
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…
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:
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.