Extensions of the math library: snake_case aliases for the built-in functions, scaling of sizes to the screen resolution and checks for even, odd and divisible numbers. Numbers get the math library as their methods here, so that n:floor() and n:clamp(0, 3) work. The Time and Unit classes add their constructors and converters to the library as well, as in math.minutes(5) and math.meters(2). This file also defines the util functions for hexadecimal numbers and 2D geometry.

Summary

Functions

Checks whether a number is divisible by another number without a remainder.
even(num)shared
Checks whether a number is even.
odd(num)shared
Checks whether a number is odd.
Scales a size that was designed for a 1080 pixels tall screen to the current screen height.
Scales a width and a height that were designed for a 1920x1080 screen to the current screen resolution.
Scales a size that was designed for a 1920 pixels wide screen to the current screen width.

Functions

math.divisible(num, factor)

shared lib/stdlib/sh_math.lua:195

Checks whether a number is divisible by another number without a remainder.

Parameters

  • num Number
  • factor Number divisor

Returns

  • Boolean

math.even(num)

shared lib/stdlib/sh_math.lua:180

Checks whether a number is even.

Parameters

  • num Number

Returns

  • Boolean

math.odd(num)

shared lib/stdlib/sh_math.lua:187

Checks whether a number is odd.

Parameters

  • num Number

Returns

  • Boolean

math.scale(size)

shared lib/stdlib/sh_math.lua:151

Scales a size that was designed for a 1080 pixels tall screen to the current screen height. Clientside only, since it depends on the screen resolution.

Parameters

  • size Number size at 1080p

Returns

  • Number scaled size, rounded down

math.scale_size(x, y)

shared lib/stdlib/sh_math.lua:168

Scales a width and a height that were designed for a 1920x1080 screen to the current screen resolution. Clientside only.

Parameters

  • x Number width at 1920x1080
  • y Number height at 1920x1080

Returns

  • Number scaled width
  • Number scaled height

math.scale_x(size)

shared lib/stdlib/sh_math.lua:159

Scales a size that was designed for a 1920 pixels wide screen to the current screen width. Clientside only, since it depends on the screen resolution.

Parameters

  • size Number size at 1920 pixels of width

Returns

  • Number scaled size, rounded down

Defined in