Random events are something that may be tricky to create in Goldsource. Of course, you can use timed events to make things seem random, but it's time consuming, and ultimately isn't the same as a real random event. Fortunately there's a trick that allows you to do proper random triggers without any custom code required! This tutorial will explain how to do it, and suggest some uses for the technique.
The Entity Setup
The basic components you need are as follows:
- An env_beam entity
- A number of info_target entities
- A func_button to go along with each info_target
entity has a flag called "Random strike"
which is what we will be using to achieve the random effect. When this flag is enabled, the beam will, as you would expect, randomly strike the targets.
The trick happens in the placement of the entities. An env_beam
can be set up to deal damage, and a func_button
can be set up to trigger when it is damaged. See where this is going?
Knowing this, the set up is fairly simple. All that needs to be done is to place the func_button
s in the path between the two info_target
s that make up the start and end of the env_beam
Take the following steps:
- Place the func_buttons between the info_target pairs that the env_beam is using
- Set the health of the func_button entities to 1 (so they are triggered by damage)
- Set the damage dealt by the env_beam to 999999
- Enable the "Random strike" flag on the env_beam
This will make env_beam
damage the button, which will activate it. Then all you have to do is set up the button to trigger whatever you want it to do!
This is the entity set up:
2D view top 2D view side
And here is a 3D image with explanation:
3D view illustrated
The most important thing here is the "Random strike"
flag on the env_beam
. It allows it to randomly pick the ending target of the beam.
For example, say there were 4 ending targets for the beam, each target would be decided randomly each time the beam strikes. Of course, you can have as many ending targets as you want!
Take a look at the properties on the env_beam
env_beam flag properties
This is the flags tab, and as we see, the main flag we need, "Random strike"
, has been turned ON
Also, in this case, env_beam
is set to be ON
at all times, but you can toggle it however you want as you normally would.
env_beam class properties
As we see here, the beam's start end targets are defined as 00bstart00
(which are the names of the info_target
s). The damage is also set to 999999
(be safe and set this value high, as lower values sometimes may not work). The "Life"
and "Strike again time"
values are set as well.
The "Strike again time"
value is the time between each strike of the beam, and the "Life"
value is how long each strike lasts (no more than 0.1 seconds is needed for this method).
If you wanted your events to trigger very quickly, you could reduce the time for the "Strike again time"
value. Along the same lines, increasing the "Strike again time"
value will make your events trigger more slowly.
You can also take advantage of the "Reset time"
property on the func_button
s - meaning that you can make sure that the random beam doesn't trigger your button too quickly.
entity uses the "Random strike"
flag to achieve random activation of buttons, which then go on to trigger another entity. You can control the speed of the events with the "Strike again time"
on the beam, as well as the "Reset time"
on the buttons.
This technique can be used to trigger anything that a button can trigger. One example is randomly swapping teleport locations in a map, like in this example map
If you're still confused, the example map contains everything you need to know to find out how to use this setup!
- Big thanks to The Mighty Atom who introduced me to this method!
The central info target has one name (starting entity)
The outer info targets need to have the same name (ending entity)
So, you have 2 entity names, start and end, where all ends are named the same. Thats how the program choses randomly.