Level Editor/Workflows/Outputs and logic
A map can wire itself up without a script, the way Hammer maps do. When something happens to one entity (a player walks into a zone, a door finishes opening, a button is pressed) it fires an output, which sends an input to another entity by its name (open that door, add one to that counter).
Some things you can build this way: a zone that opens a door half a second after a player walks in; a button that rings a bell; a timer that opens and shuts a gate every ten seconds; three switches that must all be pressed before a hatch unlocks.
The game runs it all on the server, with or without a gamemode script. What players see of it (a door moving, a button's sound) reaches them as usual.
What fires outputs and takes inputs
| Entity | Events (fires) | Inputs (takes) |
|---|---|---|
| Zone (a brush with Is Area) | OnEnter, OnExit, OnFirstEnter, OnLastExit, OnUse | Enable, Disable, Toggle |
| Door | OnOpen, OnFullyOpen, OnClose, OnFullyClosed, OnLockedUse | Open, Close, Toggle, Lock, Unlock |
| Button | OnPressed, OnUseLocked | Press, Lock, Unlock |
| Logic Relay | OnTrigger | Trigger, Enable, Disable, Toggle, CancelPending |
| Logic Timer | OnTimer | Enable, Disable, Toggle, FireTimer, RefireTime |
| Logic Counter | OutValue, OnHitMin, OnHitMax | Add, Subtract, SetValue, Enable, Disable |
Relays, timers and counters are points: click to place one. Doors and buttons are made from a selection: select the brushes and props, then choose the menu item.
Names
An output reaches its target by name:
- a door, button, relay, timer or counter by its name in the scene tree (rename it there);
- a zone by its Trigger Name.
Every entity of that name takes the input, so two zones called Spawn Room are reached together. !self means the entity firing the output.
Adding an output
- Select the entity that fires it.
- In the inspector, open Outputs and click Add Output.
- Fill in the row: On (the event), → (the target name; ▾ picks from the map's named entities), the input, and if needed a parameter (Add 5, SetValue 0, RefireTime 2.5), a delay in seconds, Once (fire only the first time) and a Team.
Each change is one undo step. Details of every field are on Inspector: Outputs.
An output that names nothing in the map is kept, but the export warns about it (output names '...', which nothing in the map is called; the game drops it) and the game ignores it.
The activator and teams
The activator is the player who set the chain off. It travels down the chain: a zone's OnEnter that triggers a relay that opens a swinging door opens it away from the player who walked in.
An output's Team fires it only when the activator is on that team. On a zone's OnFirstEnter and OnLastExit it means that team's first in and last out, whoever else is there. So OnFirstEnter → Gate, Open, Team 2 with OnLastExit → Gate, Close, Team 2 keeps a door open while any player of team 2 is in the zone, whether an enemy stands beside them or not.
Examples
A door that opens when you walk in, after half a second:
- Zone Entry: OnEnter → Gate, Open, delay 0.5.
A gate that opens and shuts every ten seconds:
- Logic Timer, Interval 10: OnTimer → Gate, Toggle.
Three switches unlock a hatch: see Logic entities.
In the game
Every fired output goes into one queue that the server works through once a tick. An output with no delay lands in the same tick it fires. A chain that keeps firing itself with no delay stops after a thousand outputs in one tick and carries on in the next. Nothing waits in the queue unless something happened, so a map's logic costs nothing while nothing is going on.
From a gamemode
A server script can join in: api.fire_input sends any input as an output would, api.counter_value reads a counter, and the _logic_event hook hears relay, timer, counter and button events. See Map entities.