wolfhacklua API 1.1 Forum

math (additions)

Five helpers the overlay adds to Lua's standard math library.

since 1.0no permission needed

The rest of math is standard Lua 5.4 (floor, sin, random, ...). See the Lua library.

Reference#

math.clamp#since 1.0

math.clamp(v: number, lo: number, hi: number): number

Keeps a number inside a range.

ParameterTypeDescription
vnumberThe value.
lonumberLower bound.
hinumberUpper bound.
ReturnsDescription
numberv limited to lo..hi.
lua
local alpha = math.clamp(health / 100, 0, 1)

math.lerp#since 1.0

math.lerp(a: number, b: number, t: number): number

Linear interpolation.

ParameterTypeDescription
anumberStart.
bnumberEnd.
tnumberProgress.
ReturnsDescription
numbera + (b - a) * t.

math.round#since 1.0

math.round(v: number): number

Rounds a number.

ParameterTypeDescription
vnumberThe value.
ReturnsDescription
numberv rounded to the nearest integer value.

math.sign#since 1.0

math.sign(v: number): number

The sign of a number.

ParameterTypeDescription
vnumberThe value.
ReturnsDescription
number-1, 0 or 1.

math.remap#since 1.0

math.remap(v: number, a: number, b: number, c: number, d: number): number

Converts a value from one range to another.

ParameterTypeDescription
vnumberThe value.
anumberInput range start.
bnumberInput range end.
cnumberOutput range start.
dnumberOutput range end.
ReturnsDescription
numberv mapped from a..b to c..d.
lua
local width = math.remap(health, 0, 100, 0, 120)
API 1.1 · source docs-src/api/math.json