Note: Command parameters are described inside the
Performs mathematical operations with vectors.
Operations for two vectors
These operations require the full syntax with no parameters omitted.
Operations for one vector
These operations only need one vector. Some of the operations also need a scalar value to be used with them. The scalar can be given in place of vector2 (the x component of vector2, if using separate-form syntax)
This command supports three types of vector notations. The preferred way is to use vector strings as the game engine uses them. A vector string looks like "23.672363,-4.000000,0.125342"; the components x, y and z are stored as floats and delimited using commas. To create a vector string from separate values, see es_createvectorstring.
When using the vector string notation with vecmath, the syntax is as above and the resulting vector is stored in one variable in vector string format (with exception of operations that return a scalar, see Operators)
Sometimes you might have the vector components stored in separate variables. You can use es_createvectorstring to combine them into a vector string, but vecmath also supports directly passing the components as separate parameters. The syntax then is:
So when you pass the vector components separately, you will also get the result in three different variables. Some operations only return a scalar value, they will save the result in <res x> variable and do not use the two other result parameters at all. You must still include them to comform to the syntax.
Take a note that if the operation does not need all of the second vector parameters, they can be omitted, but you can never omit the parameters that are before operator.
This component syntax also supports plane vectors (2D). The syntax is similar to above case:
The same rules apply to this syntax as above.
// Count the distance between two players // variables userid1 and userid2 contain valid, different userid es_xset location1 0 es_xset location2 0 es_xset vectorbw 0 es_xset distance 0 es_getplayerprop location1 server_var(userid1) "CBaseEntity.m_vecOrigin" es_getplayerprop location2 server_var(userid2) "CBaseEntity.m_vecOrigin" // Create a vector between the player locations es vecmath vectorbw server_var(location1) - server_var(location2) // Count the length of the resulting vector es vecmath distance server_var(vectorbw) length es_msg The distance between the two players is server_var(distance) game units.