Client Command by trigger_proximity

From Valve Developer Community
Jump to: navigation, search


Sometimes, either for testing or gameplay purposes, you may need the client (player(s) on your map) to execute a console command. This tutorial explains how to make a console command which executes on the start of every round in CS:S and makes a single CT activate his flashlight. If you want things to be used multiple times, read at the end of this tutorial what you need to do.

Entity requirements

Tutorial

  • Create a player spawn, if you haven't already done so.

Setting up the point_clientcommand

  • Create a point_clientcommand and name it clientcommand.
Note:It doesn't matter where you put it, but a sensible place might be near the player spawn so you don't lose it.

Setting up the trigger_proximity

  • Create a box near the player spawn. e.g. in or underneath the player spawn.
  • Tie (Ctrl+T) this box to a trigger_proximity entity. With these properties:
Class: Trigger_proximity
Keyvalues Comments
Name triggerprox_1
Parent <empty>
Origin (X Y Z) Leave untouched
Start Disabled No
Global Entity Name <empty>
Filter Name <empty>
Point to Measure From <empty>
Radius to measure within 2
  • Make an output on the trigger_proximity box:
My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnStartTouch clientcommand Command impulse 100 0.20 signed Active the flashlight on Client's side

Setting up the logic_auto

  • Create a logic_auto with this output:
My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnMapSpawn triggerprox_* Disable <none> 5.00 signed De-activate the trigger triggerprox_1
Note:IMPORTANT! Don't forget the wildcard (*)! This will automatically disable ALL trigger_proximity-entities after 5 seconds, so none of the other players executes the command, if the trigger_proximity was not fired.
ClientCommandTutorial-finalpicture best.PNG

ClientCommandTutorial-finalpicture.PNG

Multiple ...

Triggers

For more triggers, like described in this tutorial, copy the point_clientcommand and the trigger_proximity. Rename them both to make sure they are only related to each other. Now place them at more player spawns.

Player # Name point_clientcommand Name Trigger_proximity Output Trigger_proximity
Player 1 clientcommand triggerprox_1 clientcommand|Command|impulse 100|0.20|signed
Player 2 clientcommand triggerprox_2 clientcommand|Command|impulse 100|0.20|signed

etc.
Leave the logic_auto as it is, since it will automatically search for more triggerprox_ prefixes because of the wildcard (*).The clientcommand is still the same, because it will just execute the Client Command and does nothing else.

Commands

For multiple commands at a time, add more outputs to the trigger_proximity-entity:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnUser1 clientcommand Command impulse 100 0.20 signed Active the flashlight on Client's side
Entity-output-icon.png OnUser1 clientcommand Command jpeg 0.00 signed Create a screenshot on Client's side
Note:Notice that the target entity names are still the same!

Tips for commands

For this tutorial, a flashlight (impulse 100) was used as a command. There are many others that come in handy. Feel free to add your own suggestions (including the Console Command, circumstances):

Command What does it do Circumstances / Examples
impulse 100 Toggles flashlight Dark maps
bind "F12" "<command>" Binds a key for a command Binding a key to a certain command (only useful in Single Player).
alias oneclick "+attack; wait; wait; -attack" Creates a command that makes automatic weapons into one shot weapons. Once this command has been executed, use another command to bind mouse1 to oneclick Can be used to make using an assault rifle or machine gun more challenging (use in singleplayer for best results)
Note:Any command that has spaces(e.g. ent_fire <ent_name> <message>) requires double quotes. This will crash Hammer next time you load the level, as Hammer uses double quotes to separate parts of messages. Currently the only way around this(to my knowledge) is to use double quotes when compiling, which will work fine, but when exiting Hammer change the double quotes to single quotes(then save). Next time you load the map, remember to change them back to double quotes.

Sample map

sdk_client_command_start_round__by_CrabbyData.vmf (13,3 kB)
Download mirrors: