Filter Applications

== Applications for Filters ==
This tutorial explains the uses for the base Source class of entities called Filters. Filters are a cool set of entities which allow certain things to be triggered or activated based on target name, classname, damage type, or combinations of all of them. Needless to say, this has many useful applications in a level. If you are designing a form of CTF map, you'll need to use filters so players don't cheat and try to capture their own flag to get points. They're useful to ensure certain entity classes, perhaps only s, activate something, and the doesn't activate it instead.
It is assumed you have a basic knowledge of entities, triggers, and the I/O system—this is just intended as a basic breakdown of the filter types and their uses.
=== Targetname Filtering ===
Filtering by targetname uses a entity. This entity allows or disallows things via determination of the targetname of a particular entity. It needs three keyvalues. In order for a trigger to call it within the world, it requires a targetname keyvalue. In order for it to filter entities, it requires a filtername keyvalue. And in order to determine what to do with this filter, it requires a Negated keyvalue, which can either be set to 0 or 1. This last value, when set to 1, allows all but entities matching the particular targetname. When set to 0, it only allows entities with the matching targetname.
This trigger has quite a few practical applications. Let's look at the trash can sequence from Half-Life 2's train station map. How does the game know that you need to throw away the can, and not, say, one from the vending machine? How does it differentiate between takeout containers and the can you need to discard? Filters.
If we were to recreate the sequence, focusing on a filter aspect, we could name the can can, set a filter_activator_name with a filtername keyvalue of can, and set the filter's Negated keyvalue to 1. Let's say we apply this filter to a within the trashcan and have that trigger send an output of PlaySound to a nearby alarm noise. (We also need to set the flags on the trigger to recognize physics items.) So, when we drop the physics item with a targetname of can into the trigger volume, it will play the alarm sound.
=== Classname Filtering ===
Filtering by a classname utilizes a entity. The targetname and negated fields apply the same here, though the application differs. This entity has a filterclass keyvalue, which should contain the classname you wish to filter by. (For example, npc_zombie.)
While it seems like more generalized filtering, which it is, it has its own uses. For example, let's assume you're making a sequence in which you want some zombies to charge forward, and when they hit a certain point, it will trigger an alarm noise. But what if you have some other NPCs around? What if the crow can trigger the sound? Or the physics items? That wouldn't work. This is where classname filtering comes into play.
We don't need to name the zombies anything special, since we want zombies in general to fire the trigger. All we need to do is set the filter of the trigger to our filter_activator_class and enter a keyvalue called filterclass with a value of npc_zombie. Set the trigger's flags to, say, physics items and NPCs. Set up your alarm output and scatter some physics items in the map. Try to toss them through the trigger. Nothing happens. The filter_activator_class ensures the trigger is only activated by npc_zombies.
=== Damage Type Filtering ===
Damage type filtering uses, you guessed it, a . This uses the same two keyvalues as the other two filters we've discussed, but utilizes a different value for the damage: damagetype. This cannot be used as an activator (for example, to fire a trigger) but filters by what types of damage are inflicted on something. Below is a list of values for different types of damage on a damagetype key:
This can be applied on NPCs to specify what things can damage them. For example, you could make it so only burn damage hurts them. This entity is helpful in conjunction with a , which is what we will discuss next.
=== Multi-Type Filtering ===
Finally, there's multi-type filtering using a . This compares any filters you've made together, either with an AND or OR comparison, to fire something. AND will make it so all must be passed before it fires, and likewise, OR will make it so that only one must pass. This uses a combination of damage, name, or classname filtering to make a more complex filter. It utilizes similar keyvalues as those, as well. This doesn't do any actual filtering itself, it just combines other ones to make a large filter.
Happy filtering!
Category:Level Design
Category:Tutorials
Category:Filters