General-purpose helpers for string formatting, type conversion, type checking, and color math.
- ComPrint
- ComPrintLn
- EndsWith
- fmt
- GetType
- HexToRGB
- IfUndef
- IsNullOrEmpty
- IsStringAlpha
- IsStringFloat
- IsStringInt
- PathJoin
- Replace
- StartsWith
- StrJoin
- SysPrint
- SysPrintLn
- Ternary
- ToFloat
- ToInt
- ToRGB
- ToString
- Trim
Prints a formatted message to the server console.
| Parameter | Type | Description |
|---|---|---|
fmt |
string | Format string (printf-style) |
arguments |
any | Optional format arguments |
ComPrint("Hello World!");
ComPrint("Player: %s", player.name);Prints a formatted message followed by a newline to the server console. Call with no arguments to print a blank line.
| Parameter | Type | Description |
|---|---|---|
fmt |
string | Format string (printf-style) |
arguments |
any | Optional format arguments |
ComPrintLn("Player: %s", player.name);
ComPrintLn(); // blank lineReturns true if string ends with value.
| Parameter | Type | Description |
|---|---|---|
string |
string | The string to test |
value |
string | The suffix to check for |
if (EndsWith(filename, ".gsc"))
{
// handle script file
}Returns a formatted string. Equivalent to sprintf in C.
| Parameter | Type | Description |
|---|---|---|
string |
string | Format string (printf-style) |
arguments |
any | Optional format arguments |
s = fmt("%s has rank %d", player.name, rank);Returns the type name of a GSC variable as a string.
| Parameter | Type | Description |
|---|---|---|
var |
any | The variable to inspect |
type = GetType(player.name); // "string"Converts a hex color string to a normalized (0.0–1.0) RGB vector. Accepts both #RRGGBB and RRGGBB formats.
| Parameter | Type | Description |
|---|---|---|
hex |
string | Hex color string |
color = HexToRGB("#FF8800");
color = HexToRGB("FF8800");Returns var if it is defined, otherwise returns default.
| Parameter | Type | Description |
|---|---|---|
var |
any | The variable to check |
default |
any | Fallback value if var is undefined |
name = IfUndef(player.name, "Unknown");Returns true if the string is undefined or an empty string.
| Parameter | Type | Description |
|---|---|---|
str |
string | The value to check |
if (IsNullOrEmpty(player.name))
player.name = "Unknown";Returns true if the string contains only alphanumeric characters.
| Parameter | Type | Description |
|---|---|---|
str |
string | The string to test |
IsStringAlpha("abc123"); // true
IsStringAlpha("abc!"); // falseReturns true if the string represents a valid floating-point number.
| Parameter | Type | Description |
|---|---|---|
str |
string | The string to test |
IsStringFloat("3.14"); // true
IsStringFloat("abc"); // falseReturns true if the string represents a valid integer.
| Parameter | Type | Description |
|---|---|---|
str |
string | The string to test |
IsStringInt("42"); // true
IsStringInt("3.14"); // falseJoins path segments into a single filepath string, handling separators correctly.
| Parameter | Type | Description |
|---|---|---|
paths |
string | One or more path segments |
path = PathJoin("C:\\home", "cod4", "speedrun");
path = PathJoin("/home", "cod4", "speedrun");Returns a copy of source with all occurrences of search replaced by replace.
| Parameter | Type | Description |
|---|---|---|
source |
string | The original string |
search |
string | The substring to find |
replace |
string | The replacement string |
result = Replace("SR Speedrun", "Speedrun", "Deathrun"); // "SR Deathrun"Returns true if string begins with value.
| Parameter | Type | Description |
|---|---|---|
string |
string | The string to test |
value |
string | The prefix to check for |
if (StartsWith(command, "!"))
{
// handle command
}Joins all elements of a string array into a single string, separated by separator.
| Parameter | Type | Description |
|---|---|---|
array |
array | Array of strings |
separator |
string | String to insert between elements |
result = StrJoin(names, ", "); // "Alice, Bob, Charlie"Prints a formatted message to the system output (stdout).
| Parameter | Type | Description |
|---|---|---|
fmt |
string | Format string (printf-style) |
arguments |
any | Optional format arguments |
SysPrint("Hello World!");
SysPrint("Player: %s", player.name);Prints a formatted message followed by a newline to the system output. Call with no arguments to print a blank line.
| Parameter | Type | Description |
|---|---|---|
fmt |
string | Format string (printf-style) |
arguments |
any | Optional format arguments |
SysPrintLn("Player: %s", player.name);
SysPrintLn(); // blank lineReturns true if condition is truthy, otherwise returns false. Equivalent to the ? : operator in C.
| Parameter | Type | Description |
|---|---|---|
condition |
any | The condition to evaluate |
true |
any | Value returned when condition is truthy |
false |
any | Value returned when condition is falsy |
score = Ternary(player.name == "Iswenzz", 1000, 0);Converts a string, int, or vector to a float.
| Parameter | Type | Description |
|---|---|---|
var |
string | int | vector | The value to convert |
f = ToFloat("3.14");Converts a string, float, or vector to an integer.
| Parameter | Type | Description |
|---|---|---|
var |
string | float | vector | The value to convert |
i = ToInt("42");Converts 0–255 RGB channel values to a normalized (0.0–1.0) vector for use with GSC color functions.
| Parameter | Type | Description |
|---|---|---|
r |
int | Red channel (0–255) |
g |
int | Green channel (0–255) |
b |
int | Blue channel (0–255) |
color = ToRGB(255, 128, 0);Converts an int, float, or vector to a string.
| Parameter | Type | Description |
|---|---|---|
var |
int | float | vector | The value to convert |
s = ToString(player.velocity);Returns a copy of the string with leading and trailing whitespace removed.
| Parameter | Type | Description |
|---|---|---|
string |
string | The string to trim |
clean = Trim(" hello world "); // "hello world"