Two small tables that are used very often: Log for writing messages to the GameServer log, and Util for random numbers, the clock and splitting command arguments. No function needs a character.

Log

Script log lines have the [Lua] prefix.

Log.Add

Writes an information log line.

Log.Add(text)
ParameterTypeDescription
textstringContent (a number is converted to a string; any other type becomes an empty string)

Short name: LogPrint.

Log.Add("Module loaded")

Log.AddC

Writes a log line with a level (color).

Log.AddC(color, text)
ParameterTypeDescription
colorinteger1 = red (error), 3 = yellow (warning), any other value = normal information
textstringContent

Short name: LogColor(color, text): 1 = error, any other value = normal log (there is no warning level).

Log.AddC(1, "Cannot open Config.ini")
Log.AddC(3, "Reward table is empty")

Util

Util.Random

Returns a random integer in the range from min to max, both ends inclusive.

Util.Random(min, max) -> integer
ParameterTypeDescription
minintegerSmallest value (default 0)
maxintegerLargest value (default 0). If it is smaller than min, the two values are swapped

Returns: a random number. The width of the range is limited to about 2 billion at most. Short names: RandomGetNumber(n) and GetRandomValue(n) return a random number from 0 to n - 1.

local roll = Util.Random(1, 100)
if roll <= 30 then Message.Send(aIndex, 1, "You won a prize!") end

Util.LargeRandom

Returns a large random number in the range from 0 to about 4294967295.

Util.LargeRandom() -> number

No parameters.

local seed = Util.LargeRandom()

Util.GetTick

Returns the number of milliseconds elapsed since the computer started. Used to measure time intervals.

Util.GetTick() -> number

No parameters.

local t0 = Util.GetTick()
-- ... do some work ...
Log.Add("Took " .. (Util.GetTick() - t0) .. " ms")

Util.ArgNumber

Gets a numeric argument from a command string, with arguments separated by spaces or tabs.

Util.ArgNumber(text, position) -> number
ParameterTypeDescription
textstringThe string containing the arguments
positionintegerArgument position, counting from 0

Returns: the numeric value of the argument; 0 if there is no argument at that position. Short name: CommandGetArgNumber.

-- text = "10 Admin"
local n = Util.ArgNumber(text, 0)   -- 10

Util.ArgString

Gets a string argument from a command string, with arguments separated by spaces or tabs.

Util.ArgString(text, position) -> string
ParameterTypeDescription
textstringThe string containing the arguments
positionintegerArgument position, counting from 0

Returns: the argument string; an empty string if there is no argument at that position. Short name: CommandGetArgString.

-- text = "10 Admin"
local name = Util.ArgString(text, 1)   -- "Admin"