MAEngine

Globals

Global utility functions available in Lua scripts

Global Functions

These functions are available globally without any prefix.


Logging

Log

Output an info message to the console.

Log("Player connected")
Log("Score: " .. player:GetValue("score"))

print() is an alias for Log() on the server.


Warn

Output a warning message. Server only.

Warn("Player health is negative!")

Error

Output an error message. Server only.

Error("Failed to load player data")

Time Functions

GetWorldTime

Returns seconds since the server/game started.

local uptime = GetWorldTime()
Log("Server running for " .. uptime .. " seconds")

Returns: number - Seconds since start (with decimal precision)


GetDeltaTime

Returns time since the last tick/frame.

Server.Subscribe("Tick", function()
    local dt = GetDeltaTime()
    -- Use dt for frame-independent movement
end)

Returns: number - Delta time in seconds


Timestamps (Server Only)

These functions are only available on the server. The client does not have access to system time functions.

GetTimestamp

Returns the current time as an ISO 8601 UTC string.

local timestamp = GetTimestamp()
-- "2024-01-15T12:30:45Z"

DB.Create("logs", {
    event = "player_joined",
    timestamp = GetTimestamp()
})

Returns: string - ISO 8601 formatted timestamp


GetUnixTime

Returns the current Unix timestamp in seconds.

local unix = GetUnixTime()
-- 1705320645

player:SetValue("last_seen", GetUnixTime())

Returns: integer - Unix timestamp (seconds since 1970-01-01)


GetUnixTimeMillis

Returns the current Unix timestamp in milliseconds.

local unix_ms = GetUnixTimeMillis()
-- 1705320645123

-- Useful for high-precision timing
local start = GetUnixTimeMillis()
-- ... do something ...
local elapsed = GetUnixTimeMillis() - start
Log("Operation took " .. elapsed .. "ms")

Returns: integer - Unix timestamp in milliseconds


Utilities

UUID

Generate a random UUID v4.

local id = UUID()
-- "550e8400-e29b-41d4-a716-446655440000"

-- Useful for generating unique IDs
local item = {
    id = UUID(),
    name = "Sword",
    damage = 50
}
DB.Set("items", item.id, item)

Returns: string - UUID v4 string (lowercase with hyphens)


Quick Reference

FunctionAvailabilityReturnsDescription
Log(msg)Both-Info message
Warn(msg)Server-Warning message
Error(msg)Server-Error message
GetWorldTime()BothnumberSeconds since start
GetDeltaTime()BothnumberTime since last tick
GetTimestamp()ServerstringISO 8601 UTC string
GetUnixTime()ServerintegerUnix seconds
GetUnixTimeMillis()ServerintegerUnix milliseconds
UUID()BothstringRandom UUID v4

Examples

Logging Player Actions

Player.Subscribe("Spawn", function(player)
    Log("Player " .. player:GetId() .. " spawned")
end)

Events.SubscribeRemote("Trade", function(player, data)
    if not data.target_id then
        Warn("Trade request missing target_id from " .. player:GetId())
        return
    end
end)

Saving with Timestamps

Player.Subscribe("Destroy", function(player)
    DB.SetAsync("players", tostring(player:GetId()), {
        score = player:GetValue("score"),
        last_seen = GetUnixTime(),
        last_seen_readable = GetTimestamp()
    })
end)

Performance Measurement

local function measure(name, fn)
    local start = GetUnixTimeMillis()
    fn()
    local elapsed = GetUnixTimeMillis() - start
    Log(name .. " took " .. elapsed .. "ms")
end

measure("Database preload", function()
    DB.Preload("players")
    DB.Preload("items")
end)

On this page