trigger_changevalue

Modified

12-Jul-2023

Trigger_changevalue can perform arithmetic and logic operations on base-keyvalues of entities, as well as replace their private keyvalues. See trigger_copyvalue for a variant of this with more options. Supports custom keyvalues.

Keyvalues


OnDestroy Function ondestroyfn : Name of the function to use from already parsed .as script files when entity is destroyed (killed) in any way. If the function belongs to namespace, you must use prefix with the namespace name (e.g. mynamespace::MyFunction) for the keyvalue.

Name targetname : Set name of trigger_changevalue so other entities can trigger it to apply value change. Every trigger use-type works uniformly. Can be kill-targeted.

Destination entity target : Name of the entity which keyvalue is to change. This can refer to more than one.

Destination key m_iszValueName : Name of the key which's value is to be changed.

Source value m_iszNewValue : Value to be applied to the destination keyvalue.

Action m_iszValueType : This specifies how destination keyvalue and static source-value correlate. What exactly happens also depends on the types of the two.

  • 0 : Replace (= source) : Replace "Destination Key" value with "Source value".
  • 1 : Add (= old + source) : Add "Source value" to "Destination Key" value.
  • 2 : Mul (= old * source) : Multiply "Destination Key" value by "Source value".
  • 3 : Sub (= old - source) : Subtract "Source value" from "Destination Key" value.
  • 4 : Div (= old / source) : Divide "Destination Key" value by "Source value".
  • 16 : Pow (= old ^ source) : "Source value" to the power of "Destination Key" value. To keep things simple, zero to the power of zero magically equals one and taking a negative value to the power of a non-integer will cause the base to be treated as positive.
  • 12 : Mod (= old % source) : Short for "Modulo", this calculates the rest of a division. For example, 63 % 13 equals 11, because 63 - 13 = 50, 50 - 13 = 37, 37 - 13 = 24 and 24 - 13 = 11. Subtracting a fifth time would deliver a negative result and is henceforth omitted. The actual computation of this value uses a smarter, fast method; this is just for presentiveness. Usage example: You have a value in seconds, e.g. 285, and want to know how many minutes and seconds that are, so you divide by 60 and get 4.75. Omitting the 0.75 you're left with 4. For the remaining seconds, you'd calculate 285 % 60 = 45, which is the same as 60 * 0.75. Then you'd know that 285 seconds equals 4 minutes plus 45 seconds. Real numbers and negative values are supported.
  • 5 : AND (= old & source) : Bitwise operation "Destination Key" AND "Source value". The output of bitwise AND is 1 if the corresponding bits of two operands is 1. Result is saved in "Destination Key" value.
  • 6 : OR (= old | source) : Bitwise operation "Destination Key" OR "Source value". The output of bitwise OR is 1 if at least one corresponding bit of two operands is 1. Result is saved in "Destination Key" value.
  • 13 : XOR (= old ^ source) : Bitwise operation "Destination Key" XOR "Source value". The output of bitwise XOR is 1 if corresponding bits of two operands are opposite. Result is saved in "Destination Key" value.
  • 7 : NAND (= !(old & source)) : Bitwise operation "Destination Key" NAND "Source value". The output of bitwise NAND is 1 if at least one corresponding bit of two operands is 0. Result is saved in "Destination Key" value.
  • 8 : NOR (= !(old | source)) : Bitwise operation "Destination Key" NOR "Source value". The output of bitwise NOR is 1 if the corresponding bits of two operands is 0. Result is saved in "Destination Key" value.
  • 14 : NXOR (= !(old ^ source)) : Bitwise operation "Destination Key" NXOR "Source value". The output of bitwise NXOR is 1 if the corresponding bits of two operands are the same. Result is saved in "Destination Key" value.
  • 11 : Append (String concatenation) : Appends your source value to the destination keyvalue. The later must be a string, otherwise this cannot work.
  • 17 : Sin (= sin(source))
  • 18 : Cos (= cos(source))
  • 19 : Tan (= tan(source))
  • 23 : Cot (= cot(source))
  • 20 : Arcsin (= arcsin(source))
  • 21 : Arccos (= arccos(source))
  • 22 : Arctan (= arctan(source))
  • 24 : Arccot (= arccot(source))

Trigonometric funcs. I/O m_trigonometricBehaviour : When using trigonometric or arc-functions as per the "Operation"-keyvalue, this is used to determine what your input/desired output measure is. You'll usually want to stick to degrees.

  • 0 : Degrees in (out for arc.)
  • 1 : Radian measure in (out for arc.)

Append spaces (for strings) m_iAppendSpaces : When the destination keyvalue is a string, this specifies how many spaces to append after the operations. You'll usually want to use this with either the "Replace"- or "Append"-operation. This was implemented because Valve Hammer Editor omits any trailing spaces in keyvalues (but not leading ones).

Trigger after action message : Entity to trigger after the trigger_changevalue has set the new keyvalue, by targetname as usual. This is very useful when you need a chain of operations to happen in a specific order and without any delay in between. Trigger use-type is 'Toggle'.

Flags


  • 1 : Don't use X : When using vectors/arrays, this will ignore the first array. E.g., when setting render-color, specifying this flag would ignore the 'Red'-value.

  • 2 : Don't use Y : When using vectors/arrays, this will ignore the second array. E.g., when setting angles, specifying this flag would ignore the 'Yaw'-value.

  • 4 : Don't use Z : When using vectors/arrays, this will ignore the third array. E.g., when setting velocity, specifying this flag would ignore the vertical velocity.

  • 32 : Invert target value : The destination keyvalue will be multiplied with minus one before proceeding.

  • 64 : Invert source value : The source-value will be multiplied with minus one before proceeding; this change is only temporary and this keyvalue is rather useless, as you can always prepend a minus-sign to the static source-value.

Trigger_changevalue supports the use of "!activator" and "!caller" in the "Destination Entity"-field.

Trying to write a vector to a float or integer will cause the vector's length to be written. This is in respect to any ignored dimensions as per spawnflags.