Filter Applications

From Valve Developer Community
Jump to: navigation, search
Underlinked - Logo.png
This article needs more Wikipedia icon links to other articles to help Wikipedia icon integrate it into the encyclopedia. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024
English (en)日本語 (ja)Русский (ru)Translate (Translate)

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 npc_zombies, activate something, and the npc_crow 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 filter_activator_name 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 trigger_once 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 filter_activator_class 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 filter_damage_type. 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:

  • 0: GENERIC
  • 1: CRUSH
  • 2: BULLET
  • 4: SLASH
  • 8: BURN
  • 16: VEHICLE / (TRAIN Team Fortress 2)
  • 32: FALL
  • 64: BLAST
  • 128: CLUB
  • 256: SHOCK (Spawns particle with missing texture in Left 4 Dead 2)
  • 512: SONIC
  • 1024: ENERGYBEAM
  • 16384: DROWN
  • 32768: PARALYSE
  • 65536: NERVEGAS / (SAWBLADE Team Fortress 2)
  • 131072: POISON
  • 262144: RADIATION
  • 524288: DROWNRECOVER
  • 1048576: ACID / (CRITICAL Team Fortress 2)
  • 2097152: SLOWBURN
  • 4194304: REMOVENORAGDOLL
  • 16777216: FULLGIB (in Left 4 Dead series)
Note.pngNote:Some damage types are named incorrectly by default in base.fgd, instead using their GoldSource names.
  • VEHICLE is named FREEZE
  • ACID is named CHEMICAL
  • REMOVENORAGDOLL is named SLOWFREEZE
Tip.pngTip:Team Fortress 2 Team Fortress 2: Fancy damage effects such as decapitation, disintegration or ice/gold statues on death can be applied via VScript. See TakeDamageCustom function or the trigger example.


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 filter_multi, which is what we will discuss next.

Multi-Type Filtering

Finally, there's multi-type filtering using a filter_multi. 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!