trigger_copyvalue

Modified

12-Jul-2023

Provides options for performing operations on an entity's keyvalue in relation to another keyvalue of another entity. This is a beefier version of trigger_changevalue. 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_copyvalue so other entities can trigger it to apply value change (or enable constant copier when "Constant" flag is checked). With "Constant" flag enabled the behaviour is based on trigger use-type: 'On'- turn constant copier on, 'Off'- turn constant copier off, 'Toggle'- toggle constant copier. With "Constant" flag disabled all use-types are accepted to copy once. Can be kill-targeted.

Source entity netname : Name of an entity to provide a source keyvalue for the operation.

Source key m_iszSrcValueName : Name of the source entity's keyvalue - the keyvalue which shall play the later part in the operation.

Destination entity target : Name of the one entity to have a keyvalue altered.

Destination key m_iszDstValueName : Name of the keyvalue to be written on the destination entity.

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.
  • 9 : Direction to Angles
  • 10 : Angles to Direction
  • 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))

Float-to-string/-int conversion m_iFloatConversion : Specify how floats should be written to strings or converted into integers.

  • 0 : 6 decimal places (Default)
  • 1 : 5 d. p., rounded to 5 d. p.
  • 4 : 4 d. p., rounded to 4 d. p.
  • 7 : 3 d. p., rounded to 3 d. p.
  • 10 : 2 d. p., rounded to 2 d. p.
  • 13 : 1 d. p., rounded to 1 d. p.
  • 16 : Integer, rounded
  • 17 : Integer, rounded up
  • 18 : Integer, rounded down

Trigonometric funcs. I/O m_trigonometricBehaviour : When using trigonometric or arc-functions, use this to specify what measure you are using as input, or which measure you expect as output (when using arc-functions).

  • 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 and you are setting it or appending to it, this specifies how many spaces to append to the end of the new string. This was implemented because Valve Hammer Editor cuts trailing spaces in keyvalues.

Trigger after action message : Entity to trigger after the operation. This is very useful when you require a logic chain of operations to achieve a specific effect, e.g. assemble a message for a game_text entity to print. This will also be triggered for every interval in constant mode, when set. Trigger use-type is 'Toggle'.

Copy-interval (seconds) dmg : When using constant mode, use this to specify the delay between intervals where the trigger_copyvalue performs its operation, in seconds. This defaults to 0.0 seconds, meaning once every server frame.

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.

  • 8 : Constant : Makes trigger_copyvalue toggleable, and perform the specified operation on the destination keyvalue on every update interval (See "Copy-interval (seconds)" below) while it is activated.

  • 16 : Start On : Causes this entity to be enabled from level load onward, this only makes sense in combination with "Constant".

  • 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.

  • 128 : Multiple destinations : Causes trigger_copyvalue to affect all destination entities instead of only the first one found.

When source keyvalue type is a vector and destination keyvalue type is a float or integer, the length of the vector will be used for operation. Any vector-extents excluded with spawnflags will not contribute to the length. If only one vector-extent is used, it will be transmitted directly, meaning the original value, not the length/absolute value of it.

The spawnflags to exclude vector-dimensions affect source and destination keyvalue. When you set the value of a float or integer to a vector, only those vector-extents not excluded will be set to the value of the float/integer.

"Direction to Angles" and "Angles to Direction" are useful if you want to move something in the direction it's facing or force players to look in the direction of a train they are on. It's also very useful when you want to glue one entity to another and have it rotate around it. Direction vector is outputted normalized, meaning with a total length of exactly 1 unit.

You cannot copy the model from one brush entity to another brush entity, because additional actions are required for that to work. Use trigger_changemodel for that instead.

Writing to strings currently does continuously eat away at server memory because of how Valve did string-"management" in the Goldsource-engine; that means strings you have set remain in server memory unless it restarts, eventually causing memory to be full and the server to shut down. While this is rather obsolete (strings don't need much memory), try not to write them THAT often, e.g. not every server frame when in constant mode, but only every 0.3 seconds, at least when you assemble larger strings.

Constant mode with "Start On" doesn't work. Use delayed trigger_auto instead to activate this entity on map start.