Global functions (Killing Floor)

From Tripwire Interactive Wiki
Jump to: navigation, search

All of these functions are defined in Object, and are thus accessible from any class.

Integer functions

int Rand (int Max)

Returns a random number ranging from 0 to Max-1.

int Min (int A, int B)

Returns the lower of the two values.

int Max (int A, int B)

Returns the higher of the two values.

int Clamp (int V, int A, int B)

If V is smaller than A, A is returned. If V is larger than B, B is returned. In any other case V is returned.

Float functions

float Abs (float A)

Returns the absolute value of the number.

float Sin (float A)

Returns the sine of the number expressed in radius.

float Cos (float A)

Returns the cosine of the number expressed in radians.

float Tan (float A)

Returns the tangent of the number expressed in radians.

float Asin (float A)

Returns the inverse sine of the number expressed in radius.

float Acos (float A)

Returns the inverse cosine of the number expressed in radius.

float Atan (float A, float B)

Returns the inverse tangent of the number expressed in radians.

float Exp (float A)

Returns the constant "e" raised to the power of A.

float Loge (float A)

Returns the log (to the base "e") of A.

float Sqrt (float A)

Returns the square root of A.

float Square (float A)

Returns the square of A = A*A.

float FRand ()

Returns a random number from 0.0 to 1.0.

float RandRange (float Min, float Max)

Returns a random number between Min and Max.

float FMin (float A, float B)

Returns the minimum of two numbers.

float FMax (float A, float B)

Returns the maximum of two numbers.

float FClamp (float V, float A, float B)

Returns the first number clamped to the interval from A to B.

float Lerp (float Alpha, float A, float B, optional bool bClampRange)

Returns the linear interpolation between A and B.

float Smerp (float Alpha, float A, float B)

Returns an alpha-smooth nonlinear interpolation between A and B.

float Ceil (float A)

Rounds up.

float Round (float A)

Rounds normally.

String functions

int Len (coerce string S)

Returns the length of a string.

int InStr (coerce string S, coerce string t)

Returns the offset into the first string of the second string if it exists, or -1 if not.

string Mid (coerce string S, int i, optional int j)

Returns the middle part of the string S, starting and character i and including j characters (or all of them if j is not specified).

string Left (coerce string S, int i)

Returns the i leftmost characters of S.

string Right (coerce string S, int i)

Returns the i rightmost characters of S.

string Caps (coerce string S)

Returns S converted to uppercase.

string Locs (coerce string S)

Returns the lowercase representation of S.

string Chr (int i)

Returns a character from the ASCII table.

int Asc (string S)

Returns the ASCII value of a character (only the first character from the string is used).

bool Divide (coerce string Src, string Divider, out string LeftPart, out string RightPart)

Divide a string into a left and right part of the divider, returns true when divided.

int Split (coerce string Src, string Divider, out array<string> Parts)

Split a string into parts, returns the number of items the string was split into.

int StrCmp (coerce string S, coerce string T, optional int Count, optional bool bCaseSensitive)

Perform a C-like string compare. Count defines the max number of characters to compare.

string Repl (coerce string Src, coerce string Match, coerce string With, optional bool bCaseSensitive)

Replace Match with With in the source.

string Eval (bool Condition, coerce string ResultIfTrue, coerce string ResultIfFalse)

A short-hand for a string assignment based on a condition.

ReplaceText (out string Text, string Replace, string With))

Like Repl, but modifies the input string variable directly and is always case-sensitive.

EatStr (out string Dest, out string Source, int Num))

Removes Num characters from the source string and adds them at the end of the destination string.

Vector functions

float VSize (vector A)

Returns the euclidean size of the vector (the square root of the sum of the components squared).

float VSizeSquared (vector A)

Returns the euclidean size of the vector, squared. Faster than VSize.

vector Normal (vector A)

Returns a vector of size 1.0, facing in the direction of the specified vector.

Invert (out vector X, out vector Y, out vector Z)

Inverts a coordinate system specified by three axis vectors.

vector VRand ()

Returns a uniformly distributed random vector.

vector MirrorVectorByNormal (vector Vect, vector Normal)

Mirrors a vector about a specified normal vector.

Rotator functions

rotator Normalize (rotator Rot)

Returns the corresponding rotator with components between -32768 and 32767

rotator OrthoRotation (vector X, vector Y, vector Z)

Returns a rotator from three orthogonal vectors.

rotator RotRand (optional bool bRoll)

Returns a random rotator. If bRoll is false the Roll component of the rotator is 0.

GetAxes (rotator A, out vector X, out vector Y, out vector Z)

Assigns the axis vectors of A to X, Y and Z, in terms of absolute rotation, where X points forward, Y points right and Z points upwards.

GetUnAxes (rotator A, out vector X, out vector Y, out vector Z)

Assigns the axis vectors of Rot(0,0,0) to X, Y and Z, in terms of As local rotation.

Quaternion functions

Quat QuatFindBetween (Vector A, Vector B)

If A and B both have lengths of 1, this will return a quaternion representing a rotation that can turn the first vector into the second.

Quat QuatFromAxisAndAngle (Vector Axis, Float Angle)

Allows you to manually specify a quaternion by providing the axis (the facing of the quaternion) as a vector and the "roll" of that axis.

Quat QuatFromRotator (rotator A)

Converts a rotator to a quaternion.

Quat QuatInvert (Quat A)

Inverts a quaternion. The result will be facing the opposite direction and be rolled the opposite direction about its axis.

Quat QuatProduct (Quat A, Quat B)

Multiplies two Quaternions together.

vector QuatRotateVector (Quat A, vector B)

Rotates the given vector around the axis specified by the quaternion, by the amount specified by the quaternion.

Quat QuatSlerp (Quat A, Quat B, float Slerp)

Returns the spherical linear interpolation between quaternion U and V.

rotator QuatToRotator (Quat A)

Converts a quaternion to a rotator.

State functions

event BeginState ()

This event is executed during GotoState() right after the object switched to the new state.

event EndState ()

This event is executed during GotoState right before the object switches to the new state.

name GetStateName ()

Returns the object's current state name.

GotoState (optional name NewState, optional name Label)

Switches to a new state. State code execution begins at the specified label or at "Begin:" if Label is not specified.

Before the state is changed the old state's EndState() function is called. After the state changes BeginState() of the new state is called. bool IsInState (name TestState)

Returns whether the object's current state is the one specified.

Disable (name ProbeFunc)

Disables a probe function.

Enable (name ProbeFunc)

Enables a probe function.

Class / object functions

object DynamicLoadObject (string ObjectName, class ObjectClass, optional bool MayFail)

Returns a reference to a specified object, loading it from disk if necessary.

object FindObject (string ObjectName, class ObjectClass)

Similar to DynamicLoadObject(), but only returns objects that are already loaded.

array<string> GetPerObjectNames (string ININame, optional string ObjectClass, optional int MaxResults)

Returns all section names that exist in the .ini file specified by ININame which correspond to PerObjectConfig classes.

GetReferencers (Object Target, out array<Object> Referencers)

Returns a list of objects referencing the specified target object. Useful for debugging garbage collection problems.

name GetEnum (object E, coerce int i)

Returns the i-th element of the given enumeration, or an empty name if the specified index exceeds the number of elements in the enumeration.

bool ClassIsChildOf (class TestClass, class ParentClass)

Returns whether TestClass is a subclass of Parentclass. If the two classes are the same it returns true.

bool IsA (name ClassName)

Returns whether the object's class is the specified class or a subclass. Similar to ClassIsChildOf(), but only requires the class's name.

event Created ()

Called when the object is created with the new operator.

string GetPropertyText (string PropName)

Returns the value of the specified property typecasted to string. It is not possible to access default properties in this manner.

bool SetPropertyText (string PropName, string PropValue)

Assigns a value to the specified public non-constant property of an object. Only use this for properties that can be typecasted from string. Properties declared as private, protected or const cannot be altered this way, and will return false just as if the named property did not exist at all.

ClearConfig (optional string PropName)

Remove this object's section from the appropriate .ini file, and reload the script defaults for this object. If PropertyName is specified, only remove and reload that property, if found.

ResetConfig (optional string PropName)

If object's class does not have a section in the default.ini or defuser.ini, ResetConfig() now performs ClearConfig(). Otherwise, functionality is same as before. If PropertyName is specified, only reset and reload that property, if found.

SaveConfig ()

Saves the current values of config and globalconfig variables of this object to the ini file and sets them as default values for the object's class.

StaticClearConfig (optional string PropName)

Static version of ClearConfig().

StaticSaveConfig ()

Saves the default values of config and globalconfig variables of this object's class to the ini file.

Logging

Log (coerce string S, optional name Tag)

Writes a line to the log file. The line begins with the Tag (or "ScriptLog:" if Tag was not specified), followed by the log string.

Warn (coerce string S)

Same like Log(), but the line starts with "ScriptWarning:" and contains information about the object, state and function that called Warn().

string Localize (string SectionName, string KeyName, string PackageName)

Returns the string found in PackageName.int in the [SectionName] section. Logs an error if no localization for the specified string is found.

Iterator functions

AllObjects (class baseClass, out Object obj)

Iterates through all objects with the same or derived class as baseClass'.

Other functions

String GetItemName (string FullName)

Returns the class name without the package/group prefix.

StopWatch (optional bool bStop)

Call with false to start the stopwatch. Every log created with log() will be prefixed with a millisecond offset from when the stopwatch was started. Call with true to stop the stopwatch and reset the timer. When stopped the engine will output a log entry containing the total time difference.

float InterpCurveEval (InterpCurve curve, float input)

<<Description>>

InterpCurveGetInputDomain (InterpCurve curve, out float min, out float max)

<<Description>>

InterpCurveGetOutputRange (InterpCurve curve, out float min, out float max)

<<Description>>

bool PlatformIs64Bit ()

<<Description>>

bool PlatformIsMacOS ()

<<Description>>

bool PlatformIsUnix ()

<<Description>>

bool PlatformIsWindows ()

<<Description>>

bool IsOnConsole ()

Indicates if the game is being played on a video games console.

bool IsSoaking ()

Console-specific.