Class Filters - A 'filter' entity (like for RED/BLUE only) for specific classes.
Update: filter_tf_class now exists in the base tf2 fgd
Update: filter_tf_class now exists in the base tf2 fgd

Backstory:
So for the 2014 april fools gameday I went to work on a few ideas, one of the ideas I wanted to do was to take the mutants from my dm_egan_72 map and pit them off against each other in a KotH map. Unfortunately we all noticed that being a mutant engineer in dm_egan_72 was essentially useless because the sentrygun didn't crit along with your other weapons, and while a level three sentrygun is decent, it's still no match for the scout's pistol! So I needed to come up with a class filter and give engineers on the map some sort of edge. As it turns out, though, class filters were deemed impossible and have been requested on this site and others about two dozen times, each with varying responses circling 'it's not possible'. I made one, and it's possible with entities that have existed since TF2's launch!
Entities Needed:
logic_timer
filter_activator_name
logic_relay
trigger_multiple
The logic_timer:
A logic_timer with a refire interval set to 1, so it loops forever, every second firing off some outputs.. For this example I'm creating an Engineer class filter, so I target every Engineer weapon. To see a full list of class weapon entity names click here and scroll down a bit.
Here I'm targeting every engineer weapon (tf_weapon_wrench, for example), and sending them AddOutput targetname engiweapon. If you don't know yet, targetname is the Name keyvalue on every entity. Sending an entity the 'AddOutput' output allows you to change its keyvalues or even its outputs. So here, I change the tf_weapon_wrench (and others) to have the targetname 'engiweapon'.
Lastly for this logic_timer we're going to set the output: OnTimer hasengiweapon_relay Trigger.
The logic_relay:
So for the logic_relay (what the timer fires every second in addition to naming weapons), we're going to give it two outputs:
First, we're sending all 'engiweapon' on the map (all the engineer weapons) the output of: FireUser1.
Next, we're going to send all 'engiweapon' the output of: AddOutput OnUser1 !pvsplayer:AddOutput:targetname hasengiweapon::1.
What this does is it targets every engineer weapon that we've named from the timer, asks them all for the nearest PVS Player and sets that PVS Player's targetname as 'hasengiweapon'. Make sure you include the ending ::1, as this makes it run only once. You can learn more about AddOutput here, if you wish.
The filter_activator_name:
All we need to do here is set the Name of this entity to: filter_hasengiweapon. And set the 'Filter Name' keyvalue to: hasengiweapon.
A reminder that this filter is now what we'd use to target any of the PVS Players closest to existing engineer weapons on the map.
The trigger_multiple:
Put this on top of where the players spawn, and only where they spawn. If using red/blue class filters, put one of these in each spawn.
We just need this to have the output: OnStartTouch !activator 'targetname normal'. So that each time the player respawns, their name gets set back to 'normal'. That way if you changed classes, you still won't be named 'hasengiweapon'.
Now you can use the filter: 'filter_hasengiweapon' to only allow engineers to activator triggers.
Proof that it works:
1) Two bot soldiers standing on the point. 2) I get on the point, capture speed goes up to 3x. 3) I get off the point, and the capture progress halts.
Click here to watch the video walkthrough of my koth_mutants map where I show off my engineer-only capture point.
Click here to download the entities I used in my map, and the example.
Room for error:
There is a possibility that the !pvsplayer call may not select the nearest player. In my tests it worked great, but due to the vague documentation of !pvsplayer, I feel the need to mention it. It's also worth mentioning that this system may not scale up so well into more than one class, I haven't done tests with that yet.
Notes:
So with some help from Boojum about the FireOnlyOnce on the logic_relay, koth_mutants now doesn't crash anybody and is on the US server! However, during a test of it, a medic was able to capture the engi-only point, but after he died and his name was reset he was no longer able to. I'll look into how that happened in the demo.
So for the 2014 april fools gameday I went to work on a few ideas, one of the ideas I wanted to do was to take the mutants from my dm_egan_72 map and pit them off against each other in a KotH map. Unfortunately we all noticed that being a mutant engineer in dm_egan_72 was essentially useless because the sentrygun didn't crit along with your other weapons, and while a level three sentrygun is decent, it's still no match for the scout's pistol! So I needed to come up with a class filter and give engineers on the map some sort of edge. As it turns out, though, class filters were deemed impossible and have been requested on this site and others about two dozen times, each with varying responses circling 'it's not possible'. I made one, and it's possible with entities that have existed since TF2's launch!
Entities Needed:
logic_timer
filter_activator_name
logic_relay
trigger_multiple
The logic_timer:
A logic_timer with a refire interval set to 1, so it loops forever, every second firing off some outputs.. For this example I'm creating an Engineer class filter, so I target every Engineer weapon. To see a full list of class weapon entity names click here and scroll down a bit.

Here I'm targeting every engineer weapon (tf_weapon_wrench, for example), and sending them AddOutput targetname engiweapon. If you don't know yet, targetname is the Name keyvalue on every entity. Sending an entity the 'AddOutput' output allows you to change its keyvalues or even its outputs. So here, I change the tf_weapon_wrench (and others) to have the targetname 'engiweapon'.
Lastly for this logic_timer we're going to set the output: OnTimer hasengiweapon_relay Trigger.
The logic_relay:
So for the logic_relay (what the timer fires every second in addition to naming weapons), we're going to give it two outputs:

First, we're sending all 'engiweapon' on the map (all the engineer weapons) the output of: FireUser1.
Next, we're going to send all 'engiweapon' the output of: AddOutput OnUser1 !pvsplayer:AddOutput:targetname hasengiweapon::1.
What this does is it targets every engineer weapon that we've named from the timer, asks them all for the nearest PVS Player and sets that PVS Player's targetname as 'hasengiweapon'. Make sure you include the ending ::1, as this makes it run only once. You can learn more about AddOutput here, if you wish.
The filter_activator_name:
All we need to do here is set the Name of this entity to: filter_hasengiweapon. And set the 'Filter Name' keyvalue to: hasengiweapon.
A reminder that this filter is now what we'd use to target any of the PVS Players closest to existing engineer weapons on the map.

The trigger_multiple:
Put this on top of where the players spawn, and only where they spawn. If using red/blue class filters, put one of these in each spawn.
We just need this to have the output: OnStartTouch !activator 'targetname normal'. So that each time the player respawns, their name gets set back to 'normal'. That way if you changed classes, you still won't be named 'hasengiweapon'.
Now you can use the filter: 'filter_hasengiweapon' to only allow engineers to activator triggers.
Proof that it works:
1) Two bot soldiers standing on the point. 2) I get on the point, capture speed goes up to 3x. 3) I get off the point, and the capture progress halts.
Click here to watch the video walkthrough of my koth_mutants map where I show off my engineer-only capture point.
Click here to download the entities I used in my map, and the example.
Room for error:
There is a possibility that the !pvsplayer call may not select the nearest player. In my tests it worked great, but due to the vague documentation of !pvsplayer, I feel the need to mention it. It's also worth mentioning that this system may not scale up so well into more than one class, I haven't done tests with that yet.
Notes:
So with some help from Boojum about the FireOnlyOnce on the logic_relay, koth_mutants now doesn't crash anybody and is on the US server! However, during a test of it, a medic was able to capture the engi-only point, but after he died and his name was reset he was no longer able to. I'll look into how that happened in the demo.
Last edited: