[TUTORIAL] Class Filters

Egan

aa
Feb 14, 2010
1,375
1,721
Class Filters - A 'filter' entity (like for RED/BLUE only) for specific classes.

Update: filter_tf_class now exists in the base tf2 fgd

NYxhFiN.png


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.

dShTBtw.png

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:

g4hWxWN.png

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.
jWM5yt5.png


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:

UKCS-Alias

Mann vs Machine... or... Mapper vs Meta?
aa
Sep 8, 2008
1,264
816
But what if they add new weapons? That is able to break the map on that part. 1 weapon might not give problems yet, but once they can have a completely new loadout then that loadout can break.

Its a good workaround but it can still break and for that reason isnt a real class filter to me. (however, its excelent to troll gunslingers with)
 

Penguin

Clinically Diagnosed with Small Mapper's Syndrome
aa
May 21, 2009
2,039
1,484
yeah, everyone (read: I) already knew about being able to filter for entering class-specific weapon entities, but as noted above, this means that the map would inevitably break when new weapons were added. Maybe now this can finally be a reliable method, as the stream of new weapons seems to have stopped.
 

WhyNott

L1: Registered
Oct 21, 2012
27
1
Wouldn't it be simpler to use filter_activator_model with engie playermodel set? Unless there is something I'm not aware of
 

henke37

aa
Sep 23, 2011
2,075
515
Also, filtering per model is a hack. Don't compare visuals when you wanted to compare the underlaying data.

It wouldn't even work correctly, since there are at least three models for each class. And that's not counting the different skins.
 

Egan

aa
Feb 14, 2010
1,375
1,721
Sorry to necro this but I think this tutorial probably shouldn't be here anymore since Valve added an entity to filter by class in the Gun Mettle update. Filter_tf_class I believe Tumbolisu made an FGD for it (I just provided the filter values corresponding to each class).

Is there a link to his FGD or to a working prefab?
I've toyed with filter_tf_class before (with the datamaps and the keyvalues listed on the VDC) but couldn't get it working.
 

Tumby

aa
May 12, 2013
1,084
1,192
Is there a link to his FGD or to a working prefab?
I've toyed with filter_tf_class before (with the datamaps and the keyvalues listed on the VDC) but couldn't get it working.
https://www.dropbox.com/s/yzbna72rr0af8j3/zzz_filter_tf_class.fgd?dl=0
I also created the VDC page about this entity using the data I had. Obviously everyone who knows more should try to improve the page.
Speaking of which, do you still have problems making an account on the VDC? If so, just try using a different e-mail adress. I wasn't able to register on the tf2 wiki using my old adress, so I just made a new one.