Skip to main content

Masters and states

A master locks an entity, so a door, a button or a trigger with a Master only works while its master is on, and SBO has named states, logic gates and watchers that can all be masters:

  • named states that are on or off, switched with triggers
  • logic gates that combine two states
  • watchers that read the states of doors, monsters, lights and other entities

See the Masters and multisource guide for small setups that use them.

Masters​

The Master key (master) holds the name of a master entity. These entities can be masters:

MasterIt is on while
multisourceEvery entity that targets it has switched its input on, and its global state is On if you set one
env_stateIt is on
calc_stateIts logic result is true
trigger_compareIts comparison passes, worked out for the activator of the locked entity
player_hasweaponThe activator is a player who carries the weapon it names, or any weapon if you leave the weapon empty
player_hasinventoryThe activator carries the item it names, or the team has it when the item is shared
env_global with the flag Act as Master (4)Its global state is On
multi_watcherThe logical test of the states it watches is true
watcher_countIts comparison of how many entities aren't off is true

The game looks at the first entity with the master's name. If the name matches no entity, or matches an entity that can't be a master, nothing is locked and the entity works, and with developer 1 set in the console, the console shows Master was null or not a master!. For an env_global master, put the name of the env_global in Master, not the name of its global state. A global state that is Off, Dead or not set yet counts as off.

Inverted masters​

A ~ in front of the master's name makes the master work the other way round, so a door with the master ~alarm only opens while the env_state named alarm is off.

env_stateFeaturefulSpirit of Half-Life​

An env_state is a named state that is either on or off. Other entities can use it as a master, and it fires targets when it changes. Triggers switch it like this:

TriggerWhat it does
OnTurns it on, or does nothing if it is already on
OffTurns it off, or does nothing if it is already off
ToggleSwitches it to the other state
KeyWhat it does
turnontime, turnofftimeHow many seconds it takes to turn on or off. As a master, it only counts as on once the turn-on time is over, and it counts as off from the moment it starts turning off
targetGets On when the state turns on and Off when it turns off
noise1, noise2noise1 gets Toggle when the state turns on, and noise2 gets Toggle when it turns off
masterWhile its own master is off, it ignores every trigger
round_resetIf you set Yes, it goes back to the state it had when the map loaded at each round start, without firing anything. See Round hooks for more details

While it turns on, an On does nothing and an Off turns it off again, and while it turns off, an Off does nothing and an On turns it on again.

An env_state timeline: after an On it is turning on for its Turn on time and still counts as off as a master, then it is on and its target gets On. After an Off it counts as off at once and its target gets Off when the Turn off time is over. An On while it turns off starts the full Turn on time again, and the target gets no Off

How an env_state turns on and off over time

Its flags are Start On (1) and Debug Mode (2). The targets it fires at the end of a turn-on or turn-off time get the env_state itself as their activator, and the other targets get the trigger's activator.

calc_stateFeatureful​

A calc_state is a logic gate that combines two operands. As a master, it is on while its result is true. When you trigger it, it sends On to its Target if the result is true and Off if it is false, and it also fires Fire when true or Fire when false.

KeyValues
left_operand, right_operandThe names of two entities, and !activator and *player work too. An operand that is a master gives its state, and any other entity counts as on
operationAND (0), OR (1), NAND (2), NOR (3), XOR (4) or NXOR (5)
left_fallback, right_fallbackWhat an operand that doesn't exist counts as. With Error (0), nothing fires and the calc_state is off as a master. Off (1) counts the operand as off, and On (2) counts it as on

It has the flag Debug Mode (2). If calc_state entities use each other in a loop, the game stops after 32 levels and the result is false.

trigger_inoutFeaturefulSpirit of Half-Life​

A trigger_inout is a brush trigger that fires for each entity that enters it and each entity that leaves it, with that entity as the activator. It isn't a master itself, but its Fire on/off target can switch an env_state, or count with a game_counter.

KeyWhat it does
targetGets Toggle when an entity enters
m_iszAltTargetGets Toggle when an entity leaves
m_iszBothTargetGets On when an entity enters and Off when it leaves
netnameIf you set it, only an entity with this class name or name counts, and the trigger ignores its flags

By default it reacts to players. Its flags add monsters (1), pushables (4) and everything else (8), and No Clients (2) leaves players out. It checks which entities have left every 0.1 seconds, and keeps track of up to 64 entities at once. A player only counts while they are alive, so a player inside who dies, becomes a spectator or leaves the server counts as having left. While its master is off, nothing fires, but it still keeps track of the entities that enter and leave.

Entity statesSpirit of Half-Life​

Every entity is in one of five states: On, Off, Turn On, Turn Off and In Use. A multi_watcher and a watcher_count read these states, so they can react when a door opens or the last monster dies without those entities having to trigger anything. The Master key doesn't read states: it asks the master entity, and an entity that can't be a master lets everything through.

EntityOnOffTurn OnTurn OffIn Use
Doors (func_door, func_door_rotating, func_water)OpenClosedOpeningClosing
momentary_doorOpen, even a little, and standingClosedMoving openMoving closed
Buttons (func_button, func_rot_button)Pressed inOutGoing inComing back
momentary_rot_buttonTurned away from its startAt its startTurning back by itselfA player turns it
Plats (func_plat, func_platrot, func_trackchange, func_trackautochange)At the topAt the bottomGoing upGoing down
Trains (func_train, env_spritetrain, env_modeltrain)MovingStanding, also while waiting at a corner
func_guntargetOn its way, also while waiting at a cornerStopped: not started yet, triggered off, shot down or at the end of its path
func_tracktrainMoving at any speedStanding
func_rotatingTurningStandingSpeeding upSlowing down
func_pendulumSwingingStandingSwinging back to its start to stop
func_wallShowing its second textureShowing its first texture
func_wall_toggle, func_illusionary_toggleThereGone
func_breakable, func_pushableWholeBroken
light, light_spotLitSwitched off
Tanks (func_tank and the others)Active, aiming by itselfInactiveA player controls it
func_tankcontrolsA player uses themNot in use
func_rechargeHas charge leftEmptyCharging a player
Triggers (trigger_multiple, trigger_once, trigger_hurt, trigger_push and the others)A touch would set it offSwitched off, or waiting after it fired
trigger_inoutSomething it counts is insideEmpty
multi_managerFiring its targetsWaiting to be triggered
scripted_sequence, aiscripted_sequence, scripted_actionIts monster plays the actionIdleIts monster goes to it or waits thereIt lets go of its monster
scripted_sentenceIts speaker says the sentenceOtherwise
scripted_tanksequenceRunningOtherwise
MonstersAliveDeadDying
PlayersAliveDead, spectating or Game Master
monster_targetActiveInactive
env_stateOnOffTurning onTurning off
Masters (multisource, calc_state, trigger_compare, env_global with Act as Master, player_hasweapon, player_hasinventory, game_team_master, multi_watcher, watcher_count)It passesIt locks
Effects (env_beam, env_laser, env_sprite, env_bubbles, env_spark, env_model, env_beamtrail, env_dlight, env_elight, env_mirror, env_fog, env_rain, env_snow)OnOff
env_beverageHas cans leftEmpty
Every other entityAlways

A door with Starts Open is On while it is open, like any other door. A func_breakable loses its name at the moment it breaks, so a watcher doesn't find it after that.

multi_watcherSpirit of Half-Life​

A multi_watcher watches up to 64 entities, which you add as extra keys like the targets of a multi_manager, and combines their states with one of these tests: All (AND), At least one (OR), Not all (NAND), None (NOR), Exactly one (XOR) or Any number but one (XNOR).

As a master, it is on while the result is true. If it has an Entity to notify, it checks the result every 0.1 seconds and fires that entity with On or Off when the result changes. With the flag Send 'Toggle' it sends Toggle instead, and the flags Don't send On and Don't send Off stop one of the two. By default, only the state On counts as true, and the other flags make Off, Turn On, Turn Off or In Use count, or stop On from counting.

watcher_countSpirit of Half-Life​

A watcher_count counts the entities with one name whose state isn't Off and compares the count with a number. As a master, it is on while the comparison is true. It fires targets when the count goes up or down, and when the comparison becomes true or false.

Changes since 1.38​

  • env_state, calc_state, trigger_compare and trigger_inout are new
  • Inverted masters with ~ and env_global as a master are new
  • multi_watcher and watcher_count: watch other entities, for example whether a door is open, a monster is alive or a light is on, and fire their targets when that changes. They can also be used as a Master

See also​