Skip to content

OnClientEvent

A player’s client script sent an event.

The client’s KcdMp.send_event(name, payload) lands here. payload is whatever string the client sent - trust it no further than any other input from a player (parse defensively, check the pid may do what it asks). At most 30 events a second and 4 KB each per client; more is dropped.

function OnClientEvent(pid, name, payload)
-- ...
end
Parameter Type
pid number whose client sent it
name string the event’s name
payload string the string the client sent; "" when none

nothing

function OnClientEvent(pid, name, payload)
if name == "echo" then
SendClientEvent(pid, "echo", payload) -- a round-trip test
elseif name == "marker_reached" then
local n = tonumber(payload)
if n and n == nextMarker[pid] then advance(pid) end
end
end

SendClientEvent · SendClientEventToAll · SetGlobalState · the Script events group of the index