trigger_command_contact is an advanced class for sending commands to the client’s console. It solves a problem in co-op where you want to send a command to each player (e.g fog) once they touch the trigger. Using a trigger_command with a fast repeat to catch all the players is spammy and bad for the network, and may not even work: imagine players 1 and 2 riding a lift through a trigger_command. Player 2 cannot receive the command while player 1 is in the trigger, and the lift means they enter and leave it on the same frame!
trigger_command_contact offers the following guarantees:
- trigger_command_contact entities will attempt to send commands to every player which touches them
- When a command is sent successfully, further commands to that player from any trigger_command_contact fail, until they leave the successful trigger
- Otherwise commands are successful
Note that success and failure are purely internal, no network traffic is generated, so the entity is network-friendly.
Besides the more complex rules for when a command is sent, the fields work like trigger_command; in particular the message key is still used to specify the desired console command.
This class has uses in single-player as well. Because it can be used multiple times, but is not spammy, it is also a nicer way than short delay trigger_commands to create regions of your map with particular console settings like fog. In single player this class supports spawnflag 4 – see the environment variables article for details. Please note that only successful commands will update the environment variables, and in coop spawnflag 4 is ignored on this class.