ix.util

Various useful helper functions.

Functions

ix.util.DimColor(color, multiplier, alpha)

View source »

Returns a dimmed version of the given color by the given scale.

Parameters

  • color color

    Color to dim

  • multiplier number

    What to multiply the red, green, and blue values by

  • alpha number default: 255

    Alpha to use in dimmed color

Returns

  • color

    Dimmed color

Example Usage

print(ix.util.DimColor(Color(100, 100, 100, 255), 0.5))
 > 50 50 50 255

ix.util.DrawBlur(panel, amount, passes, alpha)

View source »

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 number default: 5

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

  • passes number default: 0.2

    Quality of the blur. This should be kept as default

  • alpha number default: 255

    Opacity of the blur

Example Usage

function PANEL:Paint(width, height)
	ix.util.DrawBlur(self)
end

ix.util.DrawBlurAt(x, y, width, height, amount, passes, alpha)

View source »

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

Parameters

  • x number

    X-position of the rectangle

  • y number

    Y-position of the rectangle

  • width number

    Width of the rectangle

  • height number

    Height of the rectangle

  • amount number default: 5

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

  • passes number default: 0.2

    Quality of the blur. This should be kept as default

  • alpha number default: 255

    Opacity of the blur

Example Usage

hook.Add("HUDPaint", "MyHUDPaint", function()
	ix.util.DrawBlurAt(0, 0, ScrW(), ScrH())
end)

ix.util.DrawText(text, x, y, color, alignX, alignY, font, alpha)

View source »

Draws some text with a shadow.

Parameters

  • x number

    X-position of the text

  • y number

    Y-position of the text

  • color color

    Color of the text to draw

  • alignX number default: TEXT_ALIGN_LEFT

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

  • alignY number 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 number default: color.a * 0.575

    Alpha of the shadow

ix.util.EmitQueuedSounds(entity, sounds, delay, spacing, volume, pitch)

View source »

Emits sounds one after the other from an entity.

Parameters

  • entity Entity

    Entity to play sounds from

  • sounds table

    Sound paths to play

  • delay number

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

  • spacing number

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

  • volume number

    [opt=75] The sound level of each sound

  • pitch number

    [opt=100] Pitch percentage of each sound

Returns

  • number

    How long the entire sequence of sounds will take to play

ix.util.ExpandCamelCase(input, bNoUpperFirst)

View source »

Returns a string that is the given input with spaces in between each CamelCase word. This function will ignore any words that do not begin with a capital letter. The words ooc, looc, afk, and url will be automatically transformed into uppercase text. This will not capitalize non-ASCII letters due to limitations with Lua's pattern matching.

Parameters

  • input string

    String to expand

  • bNoUpperFirst boolean default: false

    Whether or not to avoid capitalizing the first character. This is useful for lowerCamelCase

Returns

  • string

    Expanded CamelCase string

Example Usage

print(ix.util.ExpandCamelCase("HelloWorld"))
 > Hello World

ix.util.FindPlayer(identifier, bAllowPatterns)

View source »

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

Parameters

  • identifier string

    Search query

  • bAllowPatterns 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

ix.util.FormatStringNamed(format, Arguments)

View source »

Returns a string that has the named arguments in the format string replaced with the given arguments.

Parameters

  • Arguments tab or ...

    to pass to the formatted string. If passed a table, it will use that table as the lookup table for the named arguments. If passed multiple arguments, it will replace the arguments in the string in order.

Example Usage

print(ix.util.FormatStringNamed("Hi, my name is {name}.", {name = "Bobby"}))
 > Hi, my name is Bobby.
print(ix.util.FormatStringNamed("Hi, my name is {name}.", "Bobby"))
 > Hi, my name is Bobby.

ix.util.GetCharacters()

View source »

Returns an iterator for characters. The resulting key/values will be a player and their corresponding characters. This iterator skips over any players that do not have a valid character loaded.

Returns

  • Iterator

Example Usage

for client, character in ix.util.GetCharacters() do
	print(client, character)
end
> Player [1][Bot01]    character[1]
> Player [2][Bot02]    character[2]
-- etc.

ix.util.GetMaterial(materialPath)

View source »

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

Returns

  • material

    The cached material

  • OR
  • nil

    If the material doesn't exist in the filesystem

ix.util.GetStringTime(text)

View source »

Gets the amount of seconds from a given formatted string. If no time units are specified, it is assumed minutes. The valid values are as follows:

  • s - Seconds
  • m - Minutes
  • h - Hours
  • d - Days
  • w - Weeks
  • mo - Months
  • y - Years

Parameters

  • text string

    Text to interpret a length of time from

Returns

  • number

    Amount of seconds from the length interpreted from the given string

  • OR
  • 0

    If the given string does not have a valid time

Example Usage

print(ix.util.GetStringTime("5y2d7w"))
 > 162086400 -- 5 years, 2 days, 7 weeks

ix.util.GetTypeFromValue(value)

View source »

Returns the ix.type of the given value.

Parameters

  • value

    Value to get the type of

Returns

Example Usage

print(ix.util.GetTypeFromValue("hello"))
 > 2 -- i.e the value of ix.type.string

See Also

ix.util.GetUTCTime()

View source »

Gets the current time in the UTC time-zone.

Returns

  • number

    Current time in UTC

ix.util.Include(fileName, realm)

View source »

Includes a lua file based on the prefix of the file. This will automatically call include and AddCSLuaFile based on the current realm. This function should always be called shared to ensure that the client will receive the file from the server.

Parameters

  • fileName string

    Path of the Lua file to include. The path is relative to the file that is currently running this function

  • realm string optional

    Realm that this file should be included in. You should usually ignore this since it will be automatically be chosen based on the SERVER and CLIENT globals. This value should either be "server" or "client" if it is filled in manually

ix.util.IncludeDir(directory, bFromLua)

View source »

Includes multiple files in a directory.

Parameters

  • directory string

    Directory to include files from

  • bFromLua boolean optional

    Whether or not to search from the base lua/ folder, instead of contextually basing from schema/ or gamemode/

See Also

ix.util.IsColor(input)

View source »

Returns true if the given input is a color table. This is necessary since the engine IsColor function only checks for color metatables - which are not used for regular Lua color types.

Parameters

  • input

    Input to check

Returns

  • bool

    Whether or not the input is a color

ix.util.MetatableSafeTableMerge(destination, source)

View source »

Merges the contents of the second table with the content in the first one. The destination table will be modified. If element is table but not metatable object, value's elements will be changed only.

Parameters

  • destination table

    The table you want the source table to merge with

  • source table

    The table you want to merge with the destination table

Returns

  • any

    table

ix.util.PushBlur(drawFunc)

View source »

Pushes a 3D2D blur to be rendered in the world. The draw function will be called next frame in the PostDrawOpaqueRenderables hook.

Parameters

  • drawFunc function

    Function to call when it needs to be drawn

ix.util.ResetStencilValues()

View source »

Resets all stencil values to known good (i.e defaults)

ix.util.SanitizeType(type, input)

View source »

Sanitizes an input value with the given type. This function ensures that a valid type is always returned. If a valid value could not be found, it will return the default value for the type. This only works for simple types - e.g it does not work for player, character, or Steam ID types.

Parameters

  • input

    Value to sanitize

Returns

  • any

    Sanitized value

Example Usage

print(ix.util.SanitizeType(ix.type.number, "123"))
> 123
print(ix.util.SanitizeType(ix.type.bool, 1))
> true

See Also

ix.util.StringMatches(a, b)

View source »

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

ix.util.StripRealmPrefix(name)

View source »

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(ix.util.StripRealmPrefix("sv_init.lua"))
 > init.lua

ix.util.WrapText(text, maxWidth, font)

View source »

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

  • maxWidth number

    Maximum allowed width in pixels

  • font string default: "ixChatFont"

    Font to use for the text