util.event.emit

Shared

Fires an event, invoking all registered handlers with the supplied arguments


Syntax

local status = util.event.emit(
    name,
    options = nil,
    ...
)

options is positional — pass nil or omit it entirely when no routing is needed.

  • When routing options are needed — pass the options table as the second argument.
  • When no routing options are needed — omit options and pass arguments directly after name.

Only serializable values survive remote transmission. Non-serializable values are silently dropped.

  • Safe to sendnil, bool, number, string, table (including nested tables).
  • Silently dropped — functions, userdata, threads, and any other non-serializable Lua values.
  • Local-only emit (remote = false) — no serialization occurs; all Lua values are forwarded as-is.
  • Nested tables — fully supported, but deeply nested structures increase payload size and serialization cost.

Parameters

TypeNameDescription
stringnameName of the event to fire
tableoptionsRouting options table
Refer Options section
any...Arguments forwarded to every handler

Returns

TypeNameDescription
boolstatustrue on successful execution, false otherwise

Options

TypeKeyDefaultSideDescription
boolremotefalseShared• When true - transmits the event to the remote side; client sends to server, server broadcasts to all peers
• When false - fires handlers on the current side only
intpeer0ServerTarget peer-id for directed server-side remote dispatch (ignored on client)
• When 0 - broadcasts to all connected peers
• When > 0 - sends to that specific peer only

Examples

Fire a local event with arguments
util.event.on("on_damage", function(amount)
    core.engine.print("info", "Damage received:", amount)
end)

util.event.emit("on_damage", 50)
Emit an event from client to server
if core.engine.get_platform() == "client" then
    util.event.emit("on_player_ready", { remote = true }, "Tron", "sandstorm")
else
    util.event.on("on_player_ready", function(name, map)
        core.engine.print("info", "Player ready:", name, map)
    end)
end
Broadcast an event from server to all clients
if core.engine.get_platform() == "client" then
    util.event.on("on_round_start", function(round, map)
        core.engine.print("info", "Round started:", round, map)
    end)
else
    util.event.emit("on_round_start", { remote = true }, 1, "sandstorm")
end
Emit an event from server to a specific client
if core.engine.get_platform() == "client" then
    util.event.on("on_kick_notice", function(reason)
        core.engine.print("warn", "Kicked:", reason)
    end)
else
    util.event.emit("on_kick_notice", { remote = true, peer = 1963414407 }, "You were kicked")
end
Emit a event from client to server and pass a table payload
if core.engine.get_platform() == "client" then
    util.event.emit("on_player_spawn", { remote = true }, {
        name = "Tron",
        position  = { x = 0, y = 0, z = 0 },
        team = "blue"
    })
else
    util.event.on("on_player_spawn", function(data)
        core.engine.print("info", "Player spawned:", data.name, data.team)
        core.engine.iprint(data)
    end)
end

On this page