util
Shared
modkit.util holds small helpers written in Lua. They are the same on the server and on the client.
modkit.util.distance
modkit.util.distance(a, b)
modkit.util.distance(x1, y1, z1, x2, y2, z2)
| Parameter | Type | Description |
|---|---|---|
| a, b | table | anything with x, y and optional z, such as a player table. Each one can also be given as three numbers. |
Returns: the distance in Unreal units. Divide by 100 for metres.
local metres = modkit.util.distance(playerA, playerB) / 100
modkit.util.distance2d
modkit.util.distance2d(a, b) or modkit.util.distance2d(x1, y1, x2, y2)
Same as distance without the height.
modkit.util.random
modkit.util.random([min, max])
Returns: with two integers a random integer from min to max, both included. With two other numbers a random number between them. Without arguments a number from 0 to 1.
local winner = players[modkit.util.random(1, #players)]
modkit.util.round, clamp
modkit.util.round(value [, digits]) rounds to digits decimal places, default 0.
modkit.util.clamp(value, min, max) keeps value between min and max.
modkit.util.formatTime
modkit.util.formatTime(seconds)
Returns: a short text. 59 gives "59s", 125 gives "2m 05s", 3723 gives "1h 02m 03s", 90000 gives "1d 01h 00m".
player:message("Next restore in " .. modkit.util.formatTime(cooldownLeft))
modkit.util.uuid
modkit.util.uuid()
Returns: a random id in UUID version 4 format, for example "3f2b8c1e-5a7d-4e9b-a1c2-7d9e0f1a2b3c". It comes from Lua's math.random. Good for record ids, not for secrets.