Utilities

Some utility functions.  Unlike the functions in misc.lua, this file only holds HL2 specific functions.

Summary
UtilitiesSome utility functions.
Functions
execFileExecutes a file on the console.
execStringJust like execFile, except acts on newline-delimited strings.
serializeSerializes a variable.
isSandboxReturns true if the current gamemode is sandbox or is derived from sandbox.
filesInDirReturns files in directory.
queueFunctionCallAdds a function call to the queue to be called.
backupFileCopies a file to a backup file.
nameCheckChecks all players’ names at regular intervals to detect name changes.
getPlyByUID

Functions

execFile

function ULib.execFile(f,
usebasefolder)

Executes a file on the console.  Use this instead of the “exec” command when the config lies outside the cfg folder.

Parameters

fThe file, relative to the data folder.
usebasefolderAn optional boolean stating whether or not the file specified is relative to the base folder.

Revisions

v2.40No longer strips comments, removed ability to execute on players.
v2.42Added usebasefolder to conform to Garry’s API changes.

execString

function ULib.execString(f,
ply)

Just like execFile, except acts on newline-delimited strings.

Parameters

fThe string.
plyThe player to execute on.  Leave nil to execute on server.  (Ignores this param on client)

Revisions

v2.40Initial.

serialize

function ULib.serialize(v)

Serializes a variable.  It basically converts a variable into a runnable code string.  It works correctly with inline tables.

Parameters

vThe variable you wish to serialize

Returns

The string of the serialized variable

Revisions

v2.40Can now serialize entities and players

isSandbox

function ULib.isSandbox()

Returns true if the current gamemode is sandbox or is derived from sandbox.

filesInDir

function ULib.filesInDir(dir,
recurse,
root)

Returns files in directory.

Parameters

dirThe dir to look for files in.
recurse(Optional, defaults to false) If true, searches directories recursively.
rootINTERNAL USE ONLY This helps with recursive functions.

Revisions

v2.10Initial (But dragged over from GM9 archive).
v2.40Fixed (was completely broken).
v2.42Now assumes paths relative to base folder.

queueFunctionCall

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.

Parameters

fnThe function to call
...(Optional) The parameters to pass to the function

Revisions

v2.40Initial (But dragged over from UPS).

backupFile

function ULib.backupFile(f)

Copies a file to a backup file.  If a backup file already exists, makes incrementing numbered backup files.

Parameters

fThe file to backup

Returns

The pathname of the file it was backed up to.

Revisions

v2.40Initial.

nameCheck

function ULib.nameCheck()

Checks all players’ names at regular intervals to detect name changes.  Calls ULibPlayerNameChanged if the name changed.  DO NOT CALL DIRECTLY

Revisions

2.20Initial

getPlyByUID

function ULib.getPlyByUID(uid)

Parameters

uidThe uid to lookup.

Returns

The player that has the specified unique id, nil if none exists.

Revisions

v2.40Initial.
function ULib.execFile(f,
usebasefolder)
Executes a file on the console.
function ULib.execString(f,
ply)
Just like execFile, except acts on newline-delimited strings.
function ULib.serialize(v)
Serializes a variable.
function ULib.isSandbox()
Returns true if the current gamemode is sandbox or is derived from sandbox.
function ULib.filesInDir(dir,
recurse,
root)
Returns files in directory.
function ULib.queueFunctionCall(fn,
...)
Adds a function call to the queue to be called.
function ULib.backupFile(f)
Copies a file to a backup file.
function ULib.nameCheck()
Checks all players’ names at regular intervals to detect name changes.
function ULib.getPlyByUID(uid)
Close