trigger_changevalue
#
Dynamically replaces the entity keyvalue. Also can perform arithmetic, logic and string operations on the limited set of keyvalues (currently only entvars).
For vector keyvalues (e.g. if destination key is origin
or velocity
) the source value is expected to be in the form x y z
where x, y and z are numbers.
Normally the entity keyvalues are set and processed at the entity initialization phase, so changing them mid-game might bring some unexpected results, do nothing or, on other hand, break things. Therefore
trigger_changevalue
must be used with care.
Parameters #
Destination entity [LE]
- the targetname of entity(-ies) affected by a change.Destination key
- the key name of keyvalue to change. Note: this should be the internal key name, not the descriptive name featured in FGD. Toggle Smart Edit in the level editor to see the actual key name.Source value
- the value to apply in the operation. Depending on theTreat source value as
it’s either a literal value or the name of the entity to calculate Ratio/Position/Velocity from and use it as a source valueTreat source value as
- interpretation of theSource value
.Action
- this specifies how destination keyvalue and static source-value correlate. What exactly happens also depends on the types of the two. WhileReplace
works on all parameters, other actions work only on the limited set of keyvalues (as they require reading of the original value by key which is not straightforward operation in Half-Life). E.g. in the case ofAdd
action it goes asc = c + s
wherec
is the current value ands
is a source value. If both the current value and the source value are vectors, it does a component-wise operation, e.g.c.x = c.x * s.x
,c.y = c.y * s.y
,c = c.z * s.z
. If the current value is a vector and the source value is a scalar, it applies operation to all components, e.g.c.x = o.x + s
,c.y = o.y + s
,c = c.z + s
. Bitwise operators work only on integer fields likespawnflags
andeffects
.Replace
-c = s
Add
-c = c + s
Mul
-c = c * s
Sub
-c = c - s
Div
-c = c - s
. It’s an invalid operation to divide by 0. The integer division is performed if the keyvalue is integer.Mod
-c = c % s
. Calculates the Modulo, i.e. reminder of the division. Floating point numbers are converted to integers for this operation.Pow
-c
to the power ofs
.Bitwise AND
-c = c & s
. Bitwise AND. Works on integers only.Bitwise OR
-c = c | s
. Bitwise OR. Works on integers only.Bitwise XOR
-c = c ^ s
. Bitwise XOR. Works on integers only.Clear bits
-c = c & ~s
. 1-bits froms
will be removed inc
. Works on integers only.Append (String concatenation)
-c = c + s
. Works on strings only.Min
- choose the minimum value betweenc
ands
. Works on numbers and vectors (does a per-component comparison).Max
- choose the maximum value betweenc
ands
. Works on numbers and vectors (does a per-component comparison).
Trigger after operation
- trigger entities after the value was set. This can call anothertrigger_changevalue
without any delay so it’s useful for chained operations.
Spawnflags #
Don't use X
- when performing action on vector keyvalue, leave the X as is.Don't use Y
- when performing action on vector keyvalue, leave the Y as is.Don't use Z
- when performing action on vector keyvalue, leave the Z as is.
Reaction to use-type #
The use-type is ignored.
Examples #
Make something non-solid #
Let’s say you want to make some brush entity, e.g. func_door
, non-solid.
- Set
Destination key
tosolid
. - Set
Source value
to0
. - Set
Action
toReplace
(default).
Set the body of the model #
- Set
Destination key
tobody
. - Set
Source value
to the desired body number`. - Set
Action
toReplace
(default).
The real case examples:
- Adding or removing the G-man’s phone in his Opposing Force model.
- Setting the submodel of decorative
item_generic
(e.g. switch between unbroken and broken states of the car model).
Adding health #
Let’s say you have a func_breakable
and you want a way to increase its health dynamically.
- Set
Destination key
tohealth
. - Set
Source value
to the positive value you want. - Set
Action
toAdd
.
Setting EF_NODRAW #
EF_NODRAW is an effect bit flag which, when set, makes the entity invisible. It also makes the entity stop sending its position updates to the client, so attachments (e.g. beams) on such entities won’t work correctly, so if you want something to be invisible but keep attachments working just use render parameters.
EF_NODRAW is a bit flag and it has a value 128 internally. So to set it via trigger_changevalue
you need:
- Set
Destination key
toeffects
. - Set
Source value
to128
. - Set
Action
toBitwise OR
.
To remove the EF_NODRAW flag use Clear bits
action. To toggle the flag use Bitwise XOR
.
Appending text #
Let’s say you have a game_text
that shows some objective and the objective can be different depending on the previous events.
In the the game_text
Message Text put the part of the text, e.g. Eliminate all
(notice the space in the end).
Then, you have two trigger_changevalue
entities. Depending on some condition only one of them gets activated before showing the text.
For both trigger_changevalue
entities:
- Set
Destination entity
to the targetname ofgame_text
. - Set
Destination key
tomessage
. - Set
Action
toAppend (String concatenation)
.
Then:
- In the first
trigger_changevalue
setSource value
toaliens
. - In the second
trigger_changevalue
setSource value
tosoldiers
.
Depending on what instance got triggered, the game_text
then will show either “Eliminate all aliens” or “Eliminate all soldiers”.