Skip to content

Utilities

This page documents miscellaneous functions that don't belong to any library.

getVersion function

Returns the current version of Ratchet.

Syntax:

lua
string getVersion()

getSecret function

Reads a secret from ratchet/secrets.txt to avoid storing passwords or tokens in plugin code. Empty string will be returned if a secret by the specified key is not found.

Syntax:

lua
string getSecret( string key )

isServerLoaded function

Checks whether the server is fully loaded (mods and plugins are loaded, players can connect). This is mostly useful for a custom REST API to check whether the server is still starting.

Syntax:

lua
bool isServerLoaded()

getType function

Returns the name of an object type for a specific object.

Syntax:

lua
string getType( mixed object )

base64Encode function

Syntax:

lua
string base64Encode( string input )

base64Decode function

Syntax:

lua
string base64Decode( string input )

friendlyTime function

Converts number of seconds into human-friendly and readable format.

Syntax:

lua
string friendlyTime( int seconds )

Example:

lua
local time = friendlyTime(3600)
print(time) -- "1 hour"

getRealTime function

Retrieves a table of various useful values regarding current real time.

Syntax:

lua
table getRealTime( [ bool localTimezone = false ] )
FieldTypeRangeDescription
timestampnumber-Unix epoch in seconds
hournumber0-23Hour (24-hour format)
minutenumber0-59Minute
secondnumber0-60Second (60 for leap seconds)
yearnumber-Full year (e.g. 2025)
monthnumber1-12Month
daynumber1-31Day of month
weekdaynumber0-6Day of week (0=Sunday)
weekdayisonumber1-7ISO weekday (1=Monday, 7=Sunday)
yeardaynumber1-366Day of year
isdstboolean-Daylight saving time
datestring-ISO 8601 date (YYYY-MM-DD)
timestring-ISO 8601 time (HH:MM:SS)
datetimestring-ISO 8601 datetime (YYYY-MM-DDTHH:MM:SS)
hour12number1-12Hour (12-hour format)
ampmstring-"AM" or "PM"

Example:

lua
print(getRealTime().time) -- "18:04:23"

traceLine function

Trace a line between two points, detecting blocking object.

Syntax:

lua
bool, HitResult traceLine( Vector origin, Vector destination [, int|table<string> filter = 0, bool complex = false, table<Actor> ignoreList = {} ] )

Filter can be either channel index from the table below or a table of strings representing object types from the table even further below.

IndexChannel
0Visibility
1Camera
2Trace_BuildingStructure
3Trace_ProjectilePrecision
4Trace_BuildingGhost
5SandStormMonsterSpawn
6Trace_Interactable
7DamagePrevention_BlockNothing

Object Types

WorldStatic
WorldDynamic
Pawn
PhysicsBody
Vehicle
Destructible
Attack
Defense
Hitbox
Building_Structure
Projectile
WaterPhysics
Resource
Sandstorm
CollisionTrigger
Hazard
AudioTrigger
LootBag

printDebug function

Same as the native print function, except for prepending plugin name and highlighting the message with gray color in the Ratchet console. This message will also be saved to the ratchet.log file located in the server's folder.

Syntax:

lua
void printDebug( [ string input, ... ] )

printInfo function

Same as the native print function, except for prepending plugin name and highlighting the message with blue color in the Ratchet console. This message will also be saved to the ratchet.log file located in the server's folder.

Syntax:

lua
void printInfo( [ string input, ... ] )

printSuccess function

Same as the native print function, except for prepending plugin name and highlighting the message with green color in the Ratchet console. This message will also be saved to the ratchet.log file located in the server's folder.

Syntax:

lua
void printSuccess( [ string input, ... ] )

printWarning function

Same as the native print function, except for prepending plugin name and highlighting the message with gold color in the Ratchet console. This message will also be saved to the ratchet.log file located in the server's folder.

Syntax:

lua
void printWarning( [ string input, ... ] )

printError function

Same as the native print function, except for prepending plugin name and highlighting the message with red color in the Ratchet console. This message will also be saved to the ratchet.log file located in the server's folder.

Syntax:

lua
void printError( [ string input, ... ] )

dumpAllObjects function

Writes a list of all persistent actors and all their actor components into a ratchet/dump.txt file. This is potentially heavy operation and mostly only useful for advanced debugging.

Syntax:

lua
void dumpAllObjects()