Skip to content

Util

Functions

Return Type Name Description
number util.get_tick_count() Same as GetTickCount
string[] util.str_split(string str, string delimiter) Returns tokens from a string, split with the delimiter
string util.str_random(number length)
number[] util.number_to_bytes(number number) Converts a 4 byte integer to a list of bytes
string util.str_to_bytes(string str) Converts a string of hex values to a list of bytes (FFAABBCC)
nil util.yield(number ms) Yields the current thread
number util.create_thread(function callback) Creates a tick thread that can execute natives. Returns a handle
nil util.remove_thread(number id) Removes a tick handler using its handle
number util.random_int(number min, number max) Returns a random number
number util.random_float(number min, number max) Returns a random number

Examples

-- Split a string into tokens
local tokens = util.str_split('this is a nice string', ' ')
print(tokens[1]) -- "this"

-- Convert a string hex color code into numbers
local hexstr = util.str_to_bytes('FF0000FF')
print(hexstr[1]) -- 255

-- Create a script thread, and remove it
local thread_handle = util.create_thread(function()
  print('Script thread ticking')
  util.yield(1000)
end)

util.remove_thread(thread_handle)