Small numeric helpers that the Haxe standard library doesn't ship and that game code reaches for constantly. Everything is inline, so calls vanish into the generated Lua.

Static variables

@:value(0.017453292519943295)staticinlineread onlyDEG_TO_RAD:Float = 0.017453292519943295

@:value(0.000001)staticinlineread onlyEPSILON:Float = 0.000001

@:value(57.29577951308232)staticinlineread onlyRAD_TO_DEG:Float = 57.29577951308232

Static methods

staticinlineclamp(value:Float, min:Float, max:Float):Float

staticinlineclampInt(value:Int, min:Int, max:Int):Int

staticinlinedeltaDegrees(from:Float, to:Float):Float

The signed shortest rotation from from to to, in (-180, 180]. Use this instead of plain subtraction so turning from 350° to 10° gives 20, not -340.

staticinlineinverseLerp(from:Float, to:Float, value:Float):Float

The inverse of lerp: where value sits between from and to, as 0..1.

staticinlinelerp(from:Float, to:Float, t:Float):Float

Linear interpolation. t is not clamped — pass values outside 0..1 to extrapolate.

staticinlinemap(value:Float, fromMin:Float, fromMax:Float, toMin:Float, toMax:Float):Float

Remaps value from one range onto another.

@:value({ epsilon : EPSILON })staticinlinenearlyEquals(a:Float, b:Float, epsilon:Float = EPSILON):Bool

staticinlinenormalizeDegrees(degrees:Float):Float

Wraps an angle into [0, 360).

staticinlinepick<T>(values:Array<T>):T

Picks a uniformly random element, or null for an empty array.

@:has_untypedstaticinlinerandom():Float

A random float in [0, 1).

Calls Lua's math.random directly instead of Haxe's Math.random. Haxe's version makes the generated file seed the RNG at load time with

_G.math.randomseed(_G.os.time());

and FiveM's client sandbox does not expose os at all, so that line takes the resource down before a line of your code runs:

SCRIPT ERROR: attempt to index a nil value (field 'os')

Lua 5.4 seeds itself at startup, so nothing is lost by skipping it.

staticinlinerandomFloat(min:Float, max:Float):Float

A random float in [min, max).

@:has_untypedstaticinlinerandomInt(min:Int, max:Int):Int

A random integer in [min, max], both ends included.

@:value({ decimals : 0 })staticround(value:Float, decimals:Int = 0):Float

Rounds to decimals places.

staticinlinesmoothStep(edge0:Float, edge1:Float, value:Float):Float

Smoothstep easing between two edges — a gentler alternative to lerp for camera and UI motion.