Skip to content

SendClientEvent

A named event with a string payload to one player’s client script.

The client script’s OnServerEvent(name, payload) receives it; a client without a script, or without a handler for the name, ignores it. payload is a string - format it however the two halves agree. Nothing is queued for a client that has not loaded the level yet.

The name may be at most 64 bytes and the payload at most 60000 bytes of UTF-8. A bigger event is refused: nothing is sent, the function returns false and the server log names the event - it is never cut, because a cut payload is broken JSON. Split large data over several events.

A table is sent as its JSON (JsonEncode has the rules); the client script reads it with JsonDecode and a page of the web interface receives it already read. The event also reaches every page of the player’s web interface whose events_in lets it receive the name. The names that start with kcdmp: belong to the game itself: sending one is refused with false, "reserved name", and so is a table that cannot be written as JSON (the reason is JsonEncode’s).

SendClientEvent(pid, name [, payload])
Parameter Type
pid number the player
name string the event’s name (at most 64 bytes)
payload string | table the string to send ("" without; at most 60000 bytes) - or a table, which is sent as its JSON (optional)

boolean - false when the player is not connected or the event was refused for its size, for a reserved name or for a table that cannot be written as JSON (the reason is then a second value)

-- a marker the client script draws
SendClientEvent(pid, "marker", string.format("%.1f,%.1f,%.1f", x, y, z))
-- a long list in pieces of fifty entries, each well under the limit
for first = 1, #entries, 50 do
local piece = table.concat(entries, ";", first, math.min(first + 49, #entries))
if not SendClientEvent(pid, "entries", piece) then break end
end

SendClientEventToAll · OnClientEvent · SetPlayerState · the Script events group of the index