lia.util

Various useful helper functions.

Functions

Derma_NumericRequest(strTitle, strText, strDefaultText, fnEnter, fnCancel, strButtonText, strButtonCancelText)

Displays a numeric input request dialog.

Parameters

  • strTitle String

    The title of the dialog window

  • strText String

    The text to display in the dialog

  • strDefaultText String

    The default text to display in the input field

  • fnEnter Function

    The function to call when the Enter key is pressed, with the input value as its argument

  • fnCancel Function optional

    The function to call when the dialog is canceled or closed, with the input value as its argument

  • strButtonText String optional

    The text to display on the confirmation button

  • strButtonCancelText String optional

    The text to display on the cancel button

Returns

  • any

    The created DFrame window

canFit(pos, mins, maxs, filter)

Checks if a position can fit a player's collision hull.

Parameters

  • pos Vector

    The position to check

  • mins Vector optional

    The minimum size of the collision hull

  • maxs Vector optional

    The maximum size of the collision hull

  • filter Table optional

    Entities to filter out from the collision check

Returns

  • bool

    True if the position can fit the collision hull, false otherwise

chance(chance)

Rolls a chance based on a given probability.

Parameters

  • chance Integer

    The probability of success in percentage

Returns

  • bool

    True if the chance is successful, false otherwise

chatNotify(target, ...)

Prints a message to a player's chat.

Parameters

  • target Player

    The player to receive the chat message

  • ... Table

    The message or messages to print

colorToText(color)

Converts a color object to a string representation.

Parameters

  • color Color

    The color object to convert

Returns

  • any

    A string representation of the color in the format "r,g,b,a"

dWarningMessage(message, ...)

Logs a warning message to the console.

Parameters

  • message String

    The warning message string

  • ... Table

    Additional parameters for message formatting

dateToNumber(str)

Converts a date string to a table containing date and time components.

Parameters

  • str String

    The date string in the format "YYYY-MM-DD HH:MM:SS"

Returns

  • table

    Table containing date and time components

debugLog(str)

Logs a message with a timestamp to the console.

Parameters

  • str String

    The message to be logged

drawBlur(panel, amount, passes)

Blurs the content underneath the given panel. This will fall back to a simple darkened rectangle if the player has blurring disabled.

Parameters

  • panel Panel

    Panel to draw the blur for

  • amount Float default: 5

    Intensity of the blur. This should be kept between 0 and 10 for performance reasons

  • passes Float default: 0.2

    Quality of the blur. This should be kept as default

Example Usage

function PANEL:Paint(width, height)
	lia.util.drawBlur(self)
end

drawBlurAt(x, y, w, h, amount, passes)

Draws a blurred rectangle with the given position and bounds. This shouldn't be used for panels, see lia.util.drawBlur instead.

Parameters

  • x Float

    X-position of the rectangle

  • y Float

    Y-position of the rectangle

  • w Float

    Width of the rectangle

  • h Float

    Height of the rectangle

  • amount Float default: 5

    Intensity of the blur. This should be kept between 0 and 10 for performance reasons

  • passes Float default: 0.2

    Quality of the blur. This should be kept as default

Example Usage

hook.Add("HUDPaint", "MyHUDPaint", function()
	lia.util.drawBlurAt(0, 0, ScrW(), ScrH())
end)

drawText(text, x, y, color, alignX, alignY, font, alpha)

Draws some text with a shadow.

Parameters

  • text String

    Text to draw

  • x Float

    X-position of the text

  • y Float

    Y-position of the text

  • color Color

    Color of the text to draw

  • alignX Integer default: TEXT_ALIGN_LEFT

    Horizontal alignment of the text, using one of the TEXT_ALIGN_* constants

  • alignY Integer default: TEXT_ALIGN_LEFT

    Vertical alignment of the text, using one of the TEXT_ALIGN_* constants

  • font String default: "ixGenericFont"

    Font to use for the text

  • alpha Integer default: color.a * 0.575

    Alpha of the shadow

drawTexture(material, color, x, y, w, h)

Draws a textured rectangle with a specified material and color.

Parameters

  • material String

    Material to use for the texture

  • color Color

    Color of the texture to draw

  • x Integer

    X-position of the top-left corner of the rectangle

  • y Integer

    Y-position of the top-left corner of the rectangle

  • w Integer

    Width of the rectangle

  • h Integer

    Height of the rectangle

emitQueuedSounds(entity, sounds, delay, spacing, volume, pitch)

Emits sounds one after the other from an entity.

Parameters

  • entity Entity

    Entity to play sounds from

  • sounds Table

    Sound paths to play

  • delay Float

    [opt=0] How long to wait before starting to play the sounds

  • spacing Float

    [opt=0.1] How long to wait between playing each sound

  • volume Integer

    [opt=75] The sound level of each sound

  • pitch Integer

    [opt=100] Pitch percentage of each sound

Returns

  • number

    How long the entire sequence of sounds will take to play

endCaption(text, duration)

Displays a caption message on the screen for a specified duration.

Parameters

  • text String

    The caption text to display

  • duration Integer optional

    The duration (in seconds) for which to display the caption

fetchImage(id, callback, pngParameters, imageProvider)

Fetches an image from either local data or a remote server and provides it to a callback function.

Parameters

  • id String

    The unique identifier or filename of the image

  • callback Function

    The function to call with the loaded image material as its argument, or false if the image could not be loaded

  • pngParameters String optional

    parameters for loading PNG images (default is "noclamp smooth")

  • imageProvider String optional

    URL for the remote image provider (default is "https://i.imgur.com/")

findEmptySpace(entity, filter, spacing, size, height, tolerance)

Finds empty spaces around an entity where another entity can be placed.

Parameters

  • entity Player

    The client to find empty spaces around

  • filter Table optional

    Entities to filter out from the collision check

  • spacing Integer

    Spacing between empty spaces (default is 32 units)

  • size Integer

    Size of the search grid (default is 3)

  • height Integer

    Height of the search grid (default is 36 units)

  • tolerance Integer

    Tolerance for collision checking (default is 5 units)

Returns

  • any

    Table containing positions of empty spaces

findPlayer(identifier, allowPatterns)

Attempts to find a player by matching their name or Steam ID.

Parameters

  • identifier String

    Search query

  • allowPatterns Boolean default: false

    Whether or not to accept Lua patterns in identifier

Returns

  • player

    Player that matches the given search query - this will be nil if a player could not be found

findPlayerBySteamID(SteamID)

Finds a player by their SteamID.

Parameters

  • SteamID String

    The SteamID of the player to find

Returns

  • Player

    The player object if found, nil otherwise

findPlayerBySteamID64(SteamID64)

Finds a player by their SteamID64.

Parameters

  • SteamID64 String

    The SteamID64 of the player to find

Returns

  • Player

    The player object if found, nil otherwise

findPlayerItems(client)

Finds items owned by a specified player.

Parameters

  • client Player

    The player whose items are being searched for.

Returns

  • table

    A table containing all items owned by the given player.

findPlayerItemsByClass(client, class)

Finds items of a specific class owned by a specified player.

Parameters

  • client Player

    The player whose items are being searched for.

  • class String

    The class of the items being searched for.

Returns

  • table

    A table containing all items of the specified class owned by the given player.

getAdmins()

Retrieves all online players with administrative permissions.

Returns

  • table

    Table containing all online players with administrative permissions

getAllChar()

Retrieves the SteamIDs of all connected players.

Returns

  • table

    Table containing SteamIDs of all connected players

getAllCitizenModels()

Retrieves all citizen models by searching in predefined directories.

Returns

  • table

    A table containing the paths of all found citizen models.

getAllFilesInDirectory(directory, extension)

Recursively retrieves all files with a specific extension in a given directory.

Parameters

  • directory String

    The path of the directory to search in.

  • extension String

    The file extension to filter by.

Returns

  • table

    A table containing the paths of all found files with the specified extension.

getInjuredColor(client)

Determines the color indicating the health status of a player.

Parameters

  • client Player

    The player for which to determine the color

Returns

  • any

    The color representing the player's health status

getMaterial(materialPath, materialParameters)

Returns a cached copy of the given material, or creates and caches one if it doesn't exist. This is a quick helper function. if you aren't locally storing a Material() call.

Parameters

  • materialPath String

    Path to the material

  • materialParameters String optional

Returns

  • material

    The cached material

  • OR
  • nil

    If the material doesn't exist in the filesystem

gridVector(vec, gridSize)

Rounds a vector to the nearest multiple of a given grid size.

Parameters

  • vec Vector

    Vector to be rounded

  • gridSize Integer

    Grid size to round to

Returns

  • Vector

    The rounded vector

isSteamID(value)

Checks if a given value is a SteamID.

Parameters

  • value String

    The value to check

Returns

  • bool

    True if the value is a SteamID, false otherwise

notifQuery(question, option1, option2, manualDismiss, notifType, callback)

Displays a query notification panel with options.

Parameters

  • question String

    The question or prompt to display

  • option1 String

    The text for the first option

  • option2 String

    The text for the second option

  • manualDismiss Boolean

    If true, the panel requires manual dismissal

  • notifType Integer

    The type of notification

  • callback Function

    The function to call when an option is selected, with the option index and the notice panel as arguments

Returns

  • any

    The created notification panel

notify(message, recipient)

Notifies a player or all players with a message.

Parameters

  • message String

    The message to be notified

  • recipient Player

    The player to receive the notification

notify(message)

Displays a notification message in the chat.

Parameters

  • message String

    The message to display

notifyLocalized(message, ...)

Displays a localized notification message in the chat.

Parameters

  • message String

    The message to display (localized)

  • ...

    Additional parameters for string formatting

notifyLocalized(message, recipient, ...)

Notifies a player or all players with a localized message.

Parameters

  • message String

    The localized message to be notified

  • recipient Player

    The player to receive the notification

  • ...

    Additional parameters for message formatting

playerInRadius(pos, dist)

Retrieves all players within a certain radius from a given position.

Parameters

  • pos Vector

    The center position

  • dist Integer

    The maximum distance from the center

Returns

  • table

    Table containing players within the specified radius

screenScaleH(n, bool)

Scales a value proportionally based on the screen height.

Parameters

  • n Integer

    The value to scale

  • bool Boolean

    If true, scales based on vertical resolution; if false or nil, scales based on default values

Returns

  • any

    The scaled value

screenScaleW(n, bool)

Scales a value proportionally based on the screen width.

Parameters

  • n Integer

    The value to scale

  • bool Boolean

    If true, scales based on horizontal resolution; if false or nil, scales based on default values

Returns

  • any

    The scaled value

skinFunc(name, panel, a, b, c, d, e, f, g)

Calls a named skin function with optional arguments on a panel.

Parameters

  • name String

    Name of the skin function to call

  • panel optional

    Panel to apply the skin function to

  • a optional

    Argument 1

  • b optional

    Argument 2

  • c optional

    Argument 3

  • d optional

    Argument 4

  • e optional

    Argument 5

  • f optional

    Argument 6

  • g optional

    Argument 7

Returns

  • any

    The result of the skin function call

spawnEntities(entityTable)

Spawns entities from a table of entity-position pairs.

Parameters

  • entityTable Table

    Table containing entity-position pairs

spawnProp(model, position, force, lifetime, angles, collision)

Spawns a prop at a given position with optional parameters.

Parameters

  • model String

    Model of the prop to spawn

  • position Vector

    Position to spawn the prop

  • force optional

    Force to apply to the prop

  • lifetime Integer optional

    Lifetime of the prop in seconds

  • angles Angle optional

    Angles of the prop

  • collision optional

    Collision group of the prop

Returns

  • any

    The spawned prop entity

startCaption(text, duration)

Displays a caption message on the screen for a specified duration.

Parameters

  • text String

    The caption text to display

  • duration Integer optional

    The duration (in seconds) for which to display the caption

stringMatches(a, b)

Checks to see if two strings are equivalent using a fuzzy manner. Both strings will be lowered, and will return true if the strings are identical, or if b is a substring of a.

Parameters

  • a String

    First string to check

  • b String

    Second string to check

Returns

  • bool

    Whether or not the strings are equivalent

stripRealmPrefix(name)

Removes the realm prefix from a file name. The returned string will be unchanged if there is no prefix found.

Parameters

  • name String

    String to strip prefix from

Returns

  • string

    String stripped of prefix

Example Usage

print(lia.util.stripRealmPrefix("sv_init.lua"))
 > init.lua

wrapText(text, width, font)

Wraps text so it does not pass a certain width. This function will try and break lines between words if it can, otherwise it will break a word if it's too long.

Parameters

  • text String

    Text to wrap

  • width Integer

    Maximum allowed width in pixels

  • font String default: "liaChatFont"

    Font to use for the text