String Manipulation
strRepl
Finds all occurrences of a search string and replaces them with a replacement string.The string to search in
The substring to find
The string to replace matches with
Returns a new string with all replacements made. The original string is not modified.
Examples
strColorStrip
Removes all CoD4 color codes from a string.The string containing color codes (e.g.,
^1, ^2, etc.)Returns the string with all color codes normalized to
^7 (white)Example
strTokByLen
Tokenizes a string into an array based on character length, attempting to preserve complete words.The string to tokenize
The maximum character count per token
Returns an array of string tokens, each preserving color codes
This function intelligently breaks strings at word boundaries when possible and preserves color codes across tokens.
Example: Breaking long text
toUpper
Converts a string to uppercase.The string to convert
Returns the string in uppercase
Example
toTitle
Converts a string to title case (first letter of each word capitalized).The string to convert
Returns the string in title case
Example
Type Conversion
toFloat
Converts a string, integer, or float to a float value.The value to convert to float
Returns the value as a float. If the input is an integer, returns it as-is (CoD4 will cast automatically when needed).
Examples
isArray
Checks if a variable is an array.The variable to check
Returns
true if the variable is an array, false otherwiseExample
Cryptography
sha256
Calculates the SHA-256 hash of an input string.The string to hash
Returns the SHA-256 hash as a hexadecimal string (64 characters)
Example: Password hashing
Time Functions
getEpochTime
Returns the current Unix timestamp (seconds since January 1, 1970 UTC).Returns the current Unix timestamp in seconds
Example
epochTimeToString
Converts a Unix timestamp to a formatted date/time string.The Unix timestamp to convert
0= UTC timezone1= Local timezone
The format string (uses C
strftime format specifiers)Returns the formatted date/time string
Format specifiers:
%Y= Year (4 digits)%m= Month (01-12)%d= Day (01-31)%H= Hour (00-23)%M= Minute (00-59)%S= Second (00-59)%A= Full weekday name%B= Full month name
Examples
System Operations
system
Executes a system command on the server.The system command to execute
Example: Creating a backup
The
system() function does not return command output. Use with caution in production environments.Configuration Variables (CVars)
getCvar
Gets the string value of a server console variable (cvar).The name of the cvar to retrieve
Returns the cvar value as a string
Example
getCvarInt
Gets the integer value of a server console variable.The name of the cvar to retrieve
Returns the cvar value as an integer
Example
getCvarFloat
Gets the floating-point value of a server console variable.The name of the cvar to retrieve
Returns the cvar value as a float
Example
setCvar
Sets the value of a server console variable.The name of the cvar to set
The new value for the cvar
Example
Changes to some cvars may require a map restart to take effect.
Vector Operations
vectorAdd
Adds two 3D vectors together.The first vector (x, y, z)
The second vector to add
Returns the sum of the two vectors
Example
vectorScale
Multiplies a vector by a scalar value.The vector to scale
The scalar multiplier
Returns the scaled vector
Example
Best Practices
Validate Input
Always validate and sanitize user input before using it with
system() or file operations.Use Type Checking
Use
isArray() and other type checkers to prevent runtime errors.Format Timestamps
Use
epochTimeToString() for user-friendly date displays instead of raw timestamps.Hash Sensitive Data
Use
sha256() to hash passwords and sensitive data before storing or comparing.Complete Example
Example: Player session logging system