[Tutorial/Prefab] Flag Carrier Only Doors

Logo

L3: Member
Oct 25, 2007
115
26
Here's a prefab showing how to create a door that is only opened when someone carrying the flag approaches it. I suggest playing around with the tutorial to get a good idea of how it works but I'll give a short explanation as well.

An example of how it works:

I've created a point_proximity_sensor (RedFlagProxSensor) parented to the item_teamflag (RedFlag). As the flag is carried around the RedFlagProxSensor will move along with it. The point_proximity_sensor is a way to determine distance from another entity. In this case the flagOnlyDoorMarker an info_target entity setup in the center of the door. When the flag is picked up the RedFlagProxSensor is set to enabled, otherwise (when dropped, captured or at the start of the map) it is disabled to save on the cost of the entity. When enabled this proxsensor, through the use of the 'Distance' output will Set the value on a logic_compare (FlagOnlyDoorDistance). Logic_compares are used to compare two values. Using the SetValue input sets one of these values (the initial value). The other value for this logic compare is already set to 192. This value represents the distance the flag has to be from the door for it to open. The Logic_Compare is given an output of LessThan which means that when this entity is told to compare its values if the InitialValue is less than the Compare Value the output will fire (and the door will open).

The Logic_Compare entity will not automatically open the door on its own though. So what we have to do is setup a trigger_multiple around the door much like you already (or should be) doing with your doors. This trigger_multiple will do two things. First it will close the door with an output on OnEndAllTouch. The second thing it does though is through the Output of OnStartTouchAll it tells the FlagOnlyDoorDistance to compare its values.

What this means is that whenever anyone gets close to the door the logic compare will compare to see how far away the flag is from the info_target entity we setup. If the flag is close enough (and being carried) the door will open. Otherwise it will remain shut. This effectively gives you a door that can only be opened by the flag carrier.

Except not quite! There's a few fringe situations we need to take care of. First what happens if the flag is dropped or captured near the door then someone approaches the door without picking up the flag? Under our current setup the door would open for them! That's not what we want. To fix this we add two outputs to our flag, one for OnDrop and on for OnCapture. Both outputs have the target of out logic_compare (FlagOnlyDoorDistance) and set the value to 9000. This means that while the flag is not being carried it's the same as if the flag was very far away from the door. Note that we have a small delay on these outputs so that the only activate AFTER the Proximity Sensor is disabled.

The second situation we need to handle is what if the flag, after being dropped near the door, is picked up. Under our current setup the door would remain shut unless the flag carrier moved away from the door then back towards it (activating the OnStartTouch of the trigger_multiple again). So 1 more output is added to the flag on OnPickup, FlagOnlyDoorDistance, Compare. This causes the Logic_Compare to check to see if it should open the door when the flag is picked up.

I know this all is kind of jumbled and hard to read but check out the map and hopefully it'll start to make sense.

If anyone has any questions about scaling this up (multiple doors, working with both flags, etc.) Let me know and I can help you out.
 
Last edited:

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
Now that sounds like a good idea, now you need a custom texture with a "Flag only" sign
 

Intraman

L4: Comfortable Member
Nov 4, 2007
191
0
interesting. Would it be hard to change so the door won't open for the flag carrier? Or better yet edit this so other flags or items cannot be picked up a flag carrier?
 
H

Haas

if the spawn can detect a flag carrier and make him drop it then it should be possible that you can detect is some one is carrying a flag the question is how valve did it and if we can do it the same way..
Maybe mail valve :)
Maybe its possible to use the filter.
 

Logo

L3: Member
Oct 25, 2007
115
26
Yes it's possible and I've update the tutorial to show that (any make some other changes).


There is a change to the Flag Only door: The initial value on the Logic_Compare is now 9000. This way the door will not open if no one has touched the flag yet.

How a No-Flag Carrier door differs:
It's pretty much the same except that:
1. When the flag is picked up (the onPickup output) there should be no Compare to the No-Flag Carrier door. Otherwise anytime someone picks up the flag the door will randomly open even from across the map.
2. The Logic_Compare should be changed. The OnLessThan output should tell your door to close (the flag is nearby). This way if people have the door open and the flag carrier comes by it will try to shut the door. If you want to 100% make sure the carrier cannot get through the door you'd have to setup the Force Close Flag I think to ensure that the door closes if any players try to block it (and likely will crush the player). The onGreaterThan should be changed to Open the door (if the flag isn't near then open the door).
3. Don't implement an OnDrop function on the flag to set the Logic_compare value. The reason for this is if the flag is dropped near the door you don't want the door to be able to open. Otherwise a player is able to bring the flag to the door. Drop the Flag. Back away and towards the door to open it then pick the flag back up.