Masters and multisource: locking entities
A master locks other entities, so a door, a button or a trigger with a Master only works while that master is on, and the setups below show how to build power switches, key doors, alarms and exits that open once every Fed is dead. While the master is off, the entity ignores players and triggers, and a locked button plays its locked sound. The master itself never triggers the entities it locks, so nothing happens at the moment a master turns on, and the locked entity simply works the next time someone uses it.
The first sections explain the masters you can use, followed by seven small setups you can build. See Masters and states for the full rules.
The masters
To lock an entity, put the master's name in that entity's Master key. These entities can be masters:
multisource- on while every entity that targets it has switched its input onenv_state- on and off like a switch, flipped with triggerscalc_state- combines two other masters with AND, OR and the other logic operationstrigger_compare- on while its comparison of two numbers passesplayer_hasweapon- on while the activator carries a weaponplayer_hasinventory- on while the activator carries an itemenv_globalwith the flag Act as Master - on while its global state is Onmulti_watcher- on while the states of the entities it watches pass its logical test, such as "all of these doors are closed"watcher_count- on while the number of entities of one name that aren't off passes its comparison, such as "no Fed is left alive"
Some masters give a different answer for each player, because they check the activator, which is the player who
uses the locked entity. For example, a player_hasweapon master opens a door for one player and keeps it shut for
another.
A ~ in front of the name makes the master work the other way round, so an entity with the master ~alarm works
while alarm is off.
How a multisource counts its inputs
A multisource is the master from Half-Life. Its inputs are the entities whose
Target is the name of the multisource, and the multisource finds them right after the map starts, up to 32 of
them. A multi_manager that lists the multisource as one of its targets is
an input too.
Each input is either on or off, and each time an input triggers the multisource, that input flips. The use type doesn't matter, because On, Off and Toggle all flip the input. The multisource is on while all of its inputs are on, and at the moment the last input turns on, it also fires its own Target.
This has two results you must know about:
- If an input fires twice, it is off again, so a button that someone presses twice undoes its own press. Set the
delay before reset of each input button to
-1, so it fires only once, or make the inputs fire once in a different way - When the multisource fires its Target, there is no activator, so
!activatorfinds nothing in the entities it triggers
If you set Global State Master, the multisource also needs that global state to be On before it counts as on.
Setup 1: a door that needs two buttons
A door only opens after players have pressed two buttons, in any order.
- Make two
func_buttonentities - Set Target to
bothon each button - Set delay before reset to
-1on each button, so each one stays pressed and fires only once - Make a
multisourcenamedboth, with Target set todoor1 - Make a
func_doornameddoor1

A door that opens once both buttons are pressed
When the second button is pressed, both inputs are on, and the multisource fires the door. If you want players to
open the door themselves, leave the Target of the multisource empty and set Master to both on the door.
The door then stays locked until both buttons are pressed.
Setup 2: power for a lift
A lift button only works after a player has switched the power on.
- Make a
func_buttonfor the power switch, with Target set topowerand delay before reset set to-1 - Make an
env_statenamedpower - Make a
func_buttonfor the lift, with Master set topowerand Target set to the name of the lift - Choose a Locked Sound for the lift button
Before the power is on, the lift button plays its locked sound and does nothing. The power switch sends Toggle to
power, which turns it on, and from then on the lift button works.
To make the power fail again later, trigger power with Off, for example from a
trigger_relay whose Trigger State is Off.
Setup 3: a door that locks while the alarm is on
A security door works normally, but while the alarm is on, it stays shut.
- Make an
env_statenamedalarm, and turn it on and off from your map - Make a
func_doorwith Master set to~alarm
The ~ turns the master around, so the door works while alarm is off and is locked while alarm is on. The
master only decides if the door reacts when someone uses it, so the alarm doesn't close a door that is already open.
Setup 4: either of two keys opens the vault
A vault opens if players have found the red key or the blue key, and one of them is enough.
- Make two
env_stateentities namedredandblue - Turn
redon when a player finds the red key, and turnblueon when a player finds the blue key - Make a
calc_statenamedeither, with Operand 1 set tored, Operand 2 set toblueand Operation set to OR - Set Master to
eitheron thefunc_buttonof the vault
func_buttoncalc_stateeitherenv_statered and blueA calc_state works out its result each time a locked entity asks, so the vault button works as soon as one of the
two keys is found. With Operation AND, players need both keys, and with XOR, they need exactly one of them.
Setup 5: only players with a medikit can open the infirmary
- Make a
player_hasweaponnamedmedic, with Weapon classname set toweapon_medikit - Make a
func_buttonfor the infirmary, with Master set tomedicand Target set to the name of the door
The button asks medic about the player who presses it, so it works for a player who carries the medikit and plays
its locked sound for all other players.
States: masters that watch other entities
Every entity is in a state: On, Off, Turn On, Turn Off or In Use. For example, a door is On while it is open and Turn On while it opens, a monster is On while it is alive, and a light is On while it is lit. See Entity states for the states of every entity.
A multi_watcher and a
watcher_count read these states, so they see when a door opens or the last
monster dies without the door or the monster having to trigger anything. Both are masters, and both can also fire
targets when their result changes. The other masters and the Master key don't read states.
Setup 6: a lamp that shows when both doors are closed
- Make two
func_doorentities nameddoor_aanddoor_b - Make a
lightnamedlamp, with the flag Initially dark - Make a
multi_watcher, with Logical test set to "None (NOR)" and Entity to notify set tolamp - Set the flags 'Turn On' (32) and 'Turn Off' (64) on the
multi_watcher - Turn SmartEdit off and give the
multi_watcherthe keysdoor_aanddoor_b, each with the value0
"None (NOR)" is true while no door is On. A door that opens or closes isn't On either, so without the two flags, the lamp would light while a door moves. With the flags, Turn On and Turn Off count too, so the lamp is lit only while both doors are fully closed. The watcher sends On to the lamp when the test becomes true, and Off when it becomes false.
Setup 7: the exit opens when every Fed is dead
- Give all your
monster_human_gruntentities the namefeds - Make a
watcher_countnamedcleared, with Count entities named... set tofedsand Comparison number set to0 - Set Type of comparison to "'On' when count = number" on
cleared - Set Fire on turning on to the name of the exit door on
cleared
A Fed counts while it is alive or dying, so when the last Fed has died, the count is 0 and the door opens. You can
also set Master to cleared on the button of the exit, so players can only open the exit themselves when the
area is clear. Fire when count decreases fires each time a Fed dies, for example to play a sound.
Finding out why something stays locked
- If a master's name matches no entity, or an entity that can't be a master, the entity isn't locked at all, and
with
developer 1set in the console, the console showsMaster was null or not a master! - For an
env_globalmaster, the Master key needs the name of theenv_global, not the name of its global state - An
env_stateor acalc_statewith the flag Debug Mode shows each trigger it gets and each result it works out, withdeveloper 1set in the console
Further reading
- Masters and states - every master and its keys
- Trigger modes - On, Off, Toggle and Set
- Round hooks - putting an
env_stateback at each round start - Entity states - the states of every entity