Some utility functions. Unlike the functions in misc.lua, this file only holds HL2 specific functions.
Utilities | Some utility functions. |
Functions | |
fileExists | Checks for the existence of a file by path. |
fileRead | Reads a file and returns the contents. |
fileWrite | Writes file content. |
fileAppend | Append to file content. |
fileCreateDir | Create a directory. |
fileDelete | Delete file contents. |
fileIsDir | Is file a directory? |
execFile | Executes a file on the console. |
execString | Just like execFile, except acts on newline-delimited strings. |
execFileULib | Just like execFile, except only for ULib-defined commands. |
execStringULib | Just like execString, except only for ULib-defined commands. |
serialize | Serializes a variable. |
isSandbox | Returns true if the current gamemode is sandbox or is derived from sandbox. |
filesInDir | Returns files in directory. |
queueFunctionCall | Adds a function call to the queue to be called. |
namedQueueFunctionCall | Exactly like queueFunctionCall(), but allows for separately running queues to exist. |
backupFile | Copies a file to a backup file. |
nameCheck | Calls all ULibPlayerNameChanged hooks if a player changes their name. |
getPlyByUID | |
pcallError | An adaptation of a function that used to exist before GM13, allows you to call functions safely and print errors (if it errors). |
function ULib.fileExists( f, noMount )
Checks for the existence of a file by path.
f | The path to check, rooted at the garry’s mod root directory. |
noMount | (Optional) If true, will not look in mounted directories. |
True if the file exists, false otherwise.
v2.51 | Initial revision (tired of Garry changing his API all the time). |
v2.70 | Added noMount parameter to only look in mod directory. |
function ULib.fileRead( f, noMount )
Reads a file and returns the contents. This function is not very forgiving on providing oddly formatted filepaths.
f | The file to read, rooted at the garrysmod directory. |
noMount | (Optional) If true, will not look in mounted directories. |
The file contents or nil if the file does not exist.
v2.51 | Initial revision (tired of Garry changing his API all the time). |
v2.70 | Added noMount parameter to only look in mod directory. |
function ULib.fileIsDir( f, noMount )
Is file a directory?
f | The file path to check, rooted at the garrysmod directory. |
noMount | (Optional) If true, will not look in mounted directories. |
True if dir, false otherwise.
v2.51 | Initial revision (tired of Garry changing his API all the time). |
v2.70 | Added noMount parameter to only look in mod directory. |
function ULib.execFile( f, queueName, noMount )
Executes a file on the console. Use this instead of the “exec” command when the config lies outside the cfg folder.
f | The file, relative to the garrysmod folder. |
queueName | The queue name to ULib.namedQueueFunctionCall to use. |
noMount | (Optional) If true, will not look in mounted directories. |
v2.40 | No longer strips comments, removed ability to execute on players. |
v2.50 | Added option to conform to Garry’s API changes and queueName to specify queue name to use. |
v2.51 | Removed option parameter. |
v2.70 | Added noMount parameter to only look in mod directory. |
function ULib.execString( f, queueName )
Just like execFile, except acts on newline-delimited strings.
f | The string. |
queueName | The queue name to ULib.namedQueueFunctionCall to use. |
v2.40 | Initial. |
v2.50 | Added queueName to specify queue name to use. Removed ability to execute on players. |
function ULib.execFileULib( f, safeMode, noMount )
Just like execFile, except only for ULib-defined commands. It avoids the source engine command queue, and has an additional option to only execute commands marked as “safe” (up to the command author to properly define these).
f | The file, relative to the garrysmod folder. |
safeMode | If set to true, does not run “unsafe” commands. |
noMount | (Optional) If true, will not look in mounted directories. |
v2.62 | Initial. |
function ULib.execStringULib( f, safeMode )
Just like execString, except only for ULib-defined commands. It avoids the source engine command queue, and has an additional option to only execute commands marked as “safe” (up to the command author to properly define these).
f | The string. |
safeMode | If set to true, does not run “unsafe” commands. |
v2.62 | Initial. |
function ULib.filesInDir( dir, recurse, noMount, root )
Returns files in directory.
dir | The dir to look for files in. |
recurse | (Optional, defaults to false) If true, searches directories recursively. |
noMount | (Optional) If true, will not look in mounted directories. |
root | INTERNAL USE ONLY This helps with recursive functions. |
v2.10 | Initial (But dragged over from GM9 archive). |
v2.40 | Fixed (was completely broken). |
v2.50 | Now assumes paths relative to base folder. |
v2.60 | Fix for Garry API-changes |
v2.70 | Added noMount parameter to only look in mod directory. |
function ULib.queueFunctionCall( fn, ... )
Adds a function call to the queue to be called. Guaranteed to be called sometime after the current frame. Very handy when you need to delay a call for some reason. Uses a think hook, but it’s only hooked when there’s stuff in the queue.
fn | The function to call |
... | (Optional) The parameters to pass to the function |
v2.40 | Initial (But dragged over from UPS). |
function ULib.namedQueueFunctionCall( queueName, fn, ... )
Exactly like queueFunctionCall(), but allows for separately running queues to exist.
queueName | The unique name of the queue (the queue group) |
fn | The function to call |
... | (Optional) The parameters to pass to the function |
v2.50 | Initial. |
Checks for the existence of a file by path.
function ULib.fileExists( f, noMount )
Reads a file and returns the contents.
function ULib.fileRead( f, noMount )
Writes file content.
function ULib.fileWrite( f, content )
Append to file content.
function ULib.fileAppend( f, content )
Create a directory.
function ULib.fileCreateDir( f )
Delete file contents.
function ULib.fileDelete( f )
Is file a directory?
function ULib.fileIsDir( f, noMount )
Executes a file on the console.
function ULib.execFile( f, queueName, noMount )
Just like execFile, except acts on newline-delimited strings.
function ULib.execString( f, queueName )
Just like execFile, except only for ULib-defined commands.
function ULib.execFileULib( f, safeMode, noMount )
Just like execString, except only for ULib-defined commands.
function ULib.execStringULib( f, safeMode )
Serializes a variable.
function ULib.serialize( v )
Returns true if the current gamemode is sandbox or is derived from sandbox.
function ULib.isSandbox()
Returns files in directory.
function ULib.filesInDir( dir, recurse, noMount, root )
Adds a function call to the queue to be called.
function ULib.queueFunctionCall( fn, ... )
Exactly like queueFunctionCall(), but allows for separately running queues to exist.
function ULib.namedQueueFunctionCall( queueName, fn, ... )
Copies a file to a backup file.
function ULib.backupFile( f )
Calls all ULibPlayerNameChanged hooks if a player changes their name.
function ULib.nameCheck( data )
function ULib.getPlyByUID( uid )
An adaptation of a function that used to exist before GM13, allows you to call functions safely and print errors (if it errors).
function ULib.pcallError( ... )