ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server functions
  3. triggerClientEvent

Function

triggerClientEvent

ServerEventsIdentical to MTA:SA

Sends an event from the server to one player, several players or everyone at once.

Syntax

bool triggerClientEvent([table|player targets,] string name, element source [, ...])

Arguments

targetsplayer|table, optional
A player or a table of players. If you omit it or pass root, the event goes to everyone.
namestring
Event name. The client must register it with addEvent(name, true).
sourceelement
The element the client will see as source.
...any, optional
Arguments for the handler: numbers, strings, tables and elements.

Returns

true if the event was sent.

Example

The server shows a message in the middle of the player's screen. The client does the drawing.

function showMessage(player, text)
    triggerClientEvent(player, "showMessage", resourceRoot, text)
end

addCommandHandler("hello", function(player)
    showMessage(player, "Welcome to Los Santos!")
end)

Notes

Good to know. The short form without targets also works: triggerClientEvent("name", source, ...) sends to all players.

Send only what you need. Every call goes over the network. Instead of sending the same thing every frame, send it once and let the client draw.

See also