- Documentation
- Server functions
- addRemoteHandler
Function
addRemoteHandler
Registers an event sent by the client with protection: a per-player call limit, a source check and an argument count check. Rejected calls go to the server log.
Syntax
function addRemoteHandler(string name, element element, function handler [, table options = nil])Arguments
namestring- The event name.
elementelement- The element the handler is attached to (usually
root). handlerfunction- The handler;
clientis the sending player. optionstable, optional = nillimit = { count, windowMs },sourceIsClient,maxArgs,propagate.
Returns
The function to pass to removeEventHandler.
Example
addRemoteHandler("onShopBuy", root, function(item)
outputChatBox("Kupiono: " .. tostring(item), client)
end, { limit = { 5, 10000 }, sourceIsClient = true, maxArgs = 1 })
See also
addEventRegisters a custom event with the given name so it can be triggered (triggerEvent,triggerClientEvent,triggerServerEvent) and handled (addEventHandler). WithallowRemoteTrigger = truethe event can come from the other side of the network: on the server - from a client viatriggerServerEvent, on the client - from the server viatriggerClientEvent. Without it, events from the network are rejected, which protects the server from clients faking events.addEventHandlerAttaches a function to an event. This is how you react to a player joining, dying, a key press, every frame and your own events.triggerServerEventSends an event from the player to the server, for example a button click or a menu choice.