Summary

Functions

Sends a Lua file to clients when its name marks it as client or shared.
Returns the size of a text when drawn with a font.
Converts a hexadecimal color string to a color.
Converts a single hexadecimal digit to a number.
Converts a hexadecimal number string to a number.
Includes a Lua file in the realm its prefix says.
Includes every Lua file in a directory with util.Include.
Returns whether every argument is a valid object.
Returns whether a 2D point lies inside a 2D polygon.
Returns whether the line segment from A to B intersects the segment from C to D.
Runs a callback once an entity index becomes valid.

Functions

util.AddCSLuaFile(strFile)

shared gamemodes/catwork/gamemode/core/sh_kernel.lua:1650

Sends a Lua file to clients when its name marks it as client or shared.

Matches sh_, cl_ and shared.lua. Does nothing on the client.

Parameters

  • strFile String Path of the file

Returns the size of a text when drawn with a font.

Sets the current surface font as a side effect.

Parameters

  • font String Name of the font
  • text String Text to measure

Returns

  • Number Width in pixels
  • Number Height in pixels

Converts a hexadecimal color string to a color.

Accepts RRGGBB or RRGGBBAA, with or without a leading #. Any other length returns white.

local red = util.HexToColor('#ff0000')

Parameters

  • hex String The hexadecimal color

Returns

  • Color The color; alpha is 255 unless given

Converts a single hexadecimal digit to a number.

A leading - makes the result negative. Prints an error and returns 0 when the character is not a hexadecimal digit.

Parameters

  • hex String One hexadecimal digit, case-insensitive

Returns

  • Number The digit's value, 0 to 15

See also

Converts a hexadecimal number string to a number.

Parameters

  • hex String Hexadecimal digits without a prefix, such as 'ff'

Returns

  • Number The decimal value

See also

Includes a Lua file in the realm its prefix says.

On the server, cl_ files are sent to clients, sv_ and init.lua files are included and anything else is both sent and included. On the client every file except sv_ and init.lua files is included.

Parameters

  • strFile String Path of the file

Returns

  • Any What the file returns, when it is included

util.IncludeDirectory(strDirectory, strBase, bIsRecursive)

shared gamemodes/catwork/gamemode/core/sh_kernel.lua:1667

Includes every Lua file in a directory with util.Include.

util.IncludeDirectory('libraries', true) -- catwork/gamemode/core/libraries/

Parameters

  • strDirectory String The directory
  • strBase String optional, defaults to nil Prefix for strDirectory; true uses 'catwork/gamemode/core/'
  • bIsRecursive Boolean optional, defaults to false Also include subdirectories, files first

Returns whether every argument is a valid object.

Parameters

  • ... Any Objects to check with IsValid

Returns

  • Boolean true if at least one argument was passed and all of them are valid

util.VectorIsInPoly(point, polyVertices)

shared gamemodes/catwork/gamemode/core/sh_kernel.lua:393

Returns whether a 2D point lies inside a 2D polygon.

Casts a ray from the point and counts how many polygon edges it crosses, using only the x and y components. Returns nil when the point is not a vector or the vertex list is empty.

Parameters

  • point Vector The point to test
  • polyVertices List<Vector> Polygon vertices in order; the last connects back to the first

Returns

  • Boolean Whether the point is inside the polygon

See also

util.VectorsIntersect(vFrom, vTo, vFrom2, vTo2)

shared gamemodes/catwork/gamemode/core/sh_kernel.lua:357

Returns whether the line segment from A to B intersects the segment from C to D.

Only the x and y components are used. Collinear segments count as intersecting.

Parameters

  • vFrom Vector Start of the first segment
  • vTo Vector End of the first segment
  • vFrom2 Vector Start of the second segment
  • vTo2 Vector End of the second segment

Returns

  • Boolean Whether the segments intersect

util.WaitForEntity(entIndex, callback, delay, waitTime)

shared gamemodes/catwork/gamemode/core/sh_kernel.lua:1345

Runs a callback once an entity index becomes valid.

Calls it straight away when the entity already exists, otherwise polls with a timer.

util.WaitForEntity(index, function(entity)
  print(entity:GetModel())
end)

Parameters

  • entIndex Number Entity index to wait for
  • callback Function Called with the entity
  • delay Number optional, defaults to 0 Seconds between checks
  • waitTime Number optional, defaults to 100 Maximum number of checks

Defined in