Filter Applications

From Valve Developer Community
Jump to: navigation, search
Русский 日本語

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 trainstation 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, simply "can", set a filter_activator_name with a filtername keyvalue of "can", and a Negated keyvalue of 1. If we apply this filter to a trigger_once within the trashcan, and, let's say for the sake of this tutorial, have that trigger with 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, in which a classname you wish to filter by is entered (For example, npc_zombie.)

While it seems like more generalized filtering, which it is, it has it's 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 (Again, for the sake of the tutorial, an alarm noises will be used.) 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. Setup 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, to fire a trigger, for example, 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:

Value Description
16 TRAIN <Team Fortress 2>
128 CLUB
Value Description
16384 DROWN
65536 SAWBLADE <Team Fortress 2>
131072 POISON
1048576 ACID
1048576 CRITICAL <Team Fortress 2>
2097152 SLOWBURN
Note.png Note: Some damage types are named incorrectly by default in base.fgd, instead using their GoldSource names.
  • VEHICLE is named FREEZE
  • ACID is named CHEMICAL

This can be applied on npcs, for example - An npc_combine_s will do - This can specify what things can damage it. For example, you could make it so only burn damage hurts him. 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.

Filter Summary

As you can see, Filtering is a valuable asset whether you're scripting for Singleplayer, or setting up sequences in a custom type of deathmatch. They can be extremely powerful and useful, as with any other entity, if used correctly - They are also extremely flexible - Their applications are almost endless.

Happy filtering!