lia.util

Various useful helper functions.

Functions

CreateTableUI(title, columns, data, frameWidth, frameHeight)

Displays a table UI on the client.

Parameters

  • title String

    The title of the table UI.

  • columns Table

    A table defining the columns in the table. Each entry should be a table with fields name and width. The name is the column header, and width is the width of the column in pixels.

  • data Table

    A table containing rows of data. Each row is a table with keys corresponding to the field values defined in the columns table. Each key should have a value to be displayed in the respective column.

  • frameWidth Integer optional

    The width of the frame. Default is 900.

  • frameHeight Integer optional

    The height of the frame. Default is 600.

Example Usage

local columns = {
    {name = "ID", field = "id", width = 50},
    {name = "Name", field = "name", width = 150},
}
local data = {
    {id = 1, name = "Player1"},
    {id = 2, name = "Player2"}
}
lia.util.CreateTableUI("Player List", columns, data)

CreateTableUI(client, title, columns, data, frameWidth, frameHeight)

Sends a request to the client to display a table UI.

Parameters

  • client Player

    The player to whom the UI should be sent.

  • title String

    The title of the table UI.

  • columns Table

    A table defining the columns in the table. Each entry should be a table with fields name, field, and width. The name is the column header, field is the key used to retrieve the value from the row data, and width is the width of the column in pixels.

  • data Table

    A table containing rows of data. Each row is a table with keys corresponding to the field values defined in the columns table. Each key should have a value to be displayed in the respective column.

  • frameWidth Integer optional

    The width of the frame. Default is 900.

  • frameHeight Integer optional

    The height of the frame. Default is 600.

Example Usage

local columns = {
    {name = "ID", field = "id", width = 50},
    {name = "Name", field = "name", width = 150},
}
local data = {
    {id = 1, name = "Player1"},
    {id = 2, name = "Player2"}
}
lia.util.CreateTableUI(player, "Player List", columns, data)

DrawTextOutlined(text, font, x, y, colour, xalign, outlinewidth, outlinecolour)

Draws text with an outline.

Parameters

  • text String

    The text to draw

  • font String

    The font to use

  • x Integer

    The x-coordinate to draw the text at

  • y Integer

    The y-coordinate to draw the text at

  • colour Color

    The color of the text

  • xalign

    Horizontal alignment of the text (e.g., TEXTALIGNLEFT, TEXTALIGNCENTER, TEXTALIGNRIGHT)

  • outlinewidth Integer

    The width of the outline

  • outlinecolour Color

    The color of the outline

DrawTip(x, y, w, h, text, font, textCol, outlineCol)

Draws a tip box with text.

Parameters

  • x Integer

    The x-coordinate of the top-left corner

  • y Integer

    The y-coordinate of the top-left corner

  • w Integer

    The width of the tip box

  • h Integer

    The height of the tip box

  • text String

    The text to display inside the tip box

  • font String

    The font to use

  • textCol Color

    The color of the text

  • outlineCol Color

    The color of the outline

FindPlayersInBox(mins, maxs)

Finds all players within a box defined by minimum and maximum coordinates.

Parameters

  • mins Vector

    The minimum corner of the box

  • maxs Vector

    The maximum corner of the box

Returns

  • any

    table A list of players within the box

FindPlayersInSphere(origin, radius)

Finds all players within a sphere defined by an origin point and radius.

Parameters

  • origin Vector

    The center point of the sphere

  • radius Integer

    The radius of the sphere

Returns

  • any

    table A list of players within the sphere

ShadowText(text, font, x, y, colortext, colorshadow, dist, xalign, yalign)

Draws text with a shadow effect.

Parameters

  • text String

    The text to draw

  • font String

    The font to use

  • x Integer

    The x-coordinate to draw the text at

  • y Integer

    The y-coordinate to draw the text at

  • colortext Color

    The color of the text

  • colorshadow Color

    The color of the shadow

  • dist Integer

    The distance of the shadow from the text

  • xalign

    Horizontal alignment of the text (e.g., TEXTALIGNLEFT, TEXTALIGNCENTER, TEXTALIGNRIGHT)

  • yalign

    Vertical alignment of the text (e.g., TEXTALIGNTOP, TEXTALIGNCENTER, TEXTALIGNBOTTOM)

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

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

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

findPlayerEntities(client, class)

Finds all entities of a specific class owned by a specified player. If no class is specified, finds all entities owned by the player.

Parameters

  • client Player

    The player whose entities are being searched for.

  • class optional

    The class of the entities being searched for. If not provided, all entities owned by the player are returned.

Returns

  • table

    A table containing all entities of the specified class (or all entities if no class is specified) owned by the given player.

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

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

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

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

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

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

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