This tutorial will describe how to make a button turn a light on and off- obviously with a bit of intelligence it can easily be extended to make a button do anything!
First of all, create the thing you want to turn on and off- in this case, a
light entity. Simply give it a
name (e.g.
light1) and set any other visual properties you want.
Now, we will use a model as our button base. Make a
prop_dynamic, set its
name to
button_model, and find a nice
world model for it- this tutorial will use
models/props_combine/CombineButton.mdl. This button does nothing on its own, so we need some sort of trigger.
Create a
func_button brush entity "inside" your button model, and cover it in the
toolsinvisible texture:
As the button is invisible, we don't really want it to move when used, so tick the
Don't Move flag (and the
Use Activates flag). And as this is a funky Combine button, we want a decent Combine-ish
sound (e.g.
combine blip growl).
If you want something simple like a light switch you will want to be able to "toggle" the button- i.e. switch it on and off whenever you want- by ticking the
toggle flag. If instead you want a button that takes some time before you can press it again, give it a
delay before reset value (set this to
-1 if you can only press the button once!).
Finally, we need to set the Outputs of the func_button (so it does something when we use it!). Click 'Add', and you want an Output named
OnPressed targeting entities named
light1 via input
toggle. See the image below if you get stuck. And note there are other input types (TurnOff and TurnOn, for example) which are explained in that entitys help guide.
We could finish here, but oh no, we want the button to look like its doing something when pressed! Go back to the prop_dynamic button, and click on the "Model" tab at the top of its properties. Look through the sequences there- we want the
press animation for when its pressed. So go back to the func_button and add a new output: when
OnPressed, target
button_model via the
SetAnimation input, with a parameter override of
press. Done!