ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. triggerServerEvent

Function

triggerServerEvent

ClientEventsIdentical to MTA:SA

Sends an event from the player to the server, for example a button click or a menu choice.

Syntax

bool triggerServerEvent(string name [, element source = localPlayer, ...])

Arguments

namestring
Event name. The server must register it with addEvent(name, true).
sourceelement, optional = localPlayer
The element the server will see as source.
...any, optional
Arguments for the handler on the server.

Returns

true if the event was sent.

Example

The player presses F2 and the server checks whether they can afford a car repair.

bindKey("F2", "down", function()
    triggerServerEvent("repairCar", resourceRoot)
end)

Notes

Do not trust data from the player. On the server use the client variable, not arguments sent by the player, to know who sent the event. Always check prices, rewards and permissions on the server.

Good to know. An event not registered with true is rejected, and the server triggers onPlayerTriggerInvalidEvent.

See also