From EventScripts Community Encyclopedia
Overview
Syntax:
es_math
<variable> <operator> [value]
Note: Command parameters are described inside the < and > characters. Optional parameters are contained within [ and ] characters.
Variation of this command that doesn't expand variables: es_xmath
Description
Performs a math operation on value and places it in variable. Some math operations do not need a value.
Parameters
- variable - variable where you want to store the value of math operation
- operator - Can be any of the following
- + - also can use add
- - - also can use subtract
- * - also can use multiply
- / - also can use divide
- = - also can use set
- sin - returns the sine of variable - no value used
- cos - returns the cosine of variable - no value used
- tan - returns the tangent of variable - no value used
- asin - returns the arc sine of variable - no value used
- acos - returns the arc cosine of variable - no value used
- atan - returns the arc tangent of variable - no value used
- power - raises variable to the power of value(value is the exponent)
- root - returns the nth root of variable(value is n)
- abs - returns the absolute value of variable - no value used
- int - returns the integer value of variable - no value used
- float - converts variable to a floating point - no value used
- value - Used with some math operations as called out above
Examples
// Set a variable to 0
es_setinfo myvar 0
// Add 1 to the variable
es_math myvar + 1
// Mulitply the variable by 5
es_math myvar multiply 5
// Raise variable to it's 3rd power
es_math myvar power 3
// Find the cosine of variable
es_math myvar cos
// Get the absolute value of the variable
es_math myvar abs
// Subtract the value of another server variable from the variable
es_math myvar subtract server_var(anothervar)
// Get the square root of myvar
es_math myvar root 2
Notes
- Math can only be performed on non-string variables. If you set a variable to a string it will cause an error if you later try to perform math on it.
- As noted some math operations do not require a value.
- WARNING: If <variable> has always had an integer value and you try to use a math operation with a floating point [value] it may treat [value] as an integer during the calcualtion.
- The current workaround for this is manually setting all variables involved in the operation to floats by using the 'es_xmath <variable> float' command before the operation, i.e. 'es_xmath variable1 float'.
See also
|
|