CallRemoteEvent

From Onset Developer Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
CallRemoteEvent

Type: Function
Context: Server & Client
Introduced: v1.0

Description

Calls a remote event on the remote machine. The server can call remote events for any connected player. Players (clients) can only call remote events on the server. Events are guaranteed to execute in the order sent. Keep in mind that it takes time to reach the remote machine as it's send over the network.
Remote events are independent of packages meaning you can call remote events across different packages.

Limitations

  • Maximum name length of a remote event: 128 characters
  • Maximum arguments to pass: 14
  • Valid Lua argument types: Integer, Boolean, Number, String, Table
  • Maximum String argument length: 65536 characters
  • Maximum Table argument dimensions: 5
  • Maximum Table keys: 1000 entries
  • Valid Table argument keys: Number, Integer, String (32 characters)
  • Valid Table argument values: Integer, Boolean, Number, String, Table

Syntax

CallRemoteEvent(player, EventName [, LuaArgs...])
Client Syntax
CallRemoteEvent(EventName [, LuaArgs...])

Parameters

  • player
    The player identifier to call a remote event.
  • EventName
    The name of the remote event as a string which was explicit defined by AddRemoteEvent.
  • UserArgs (optional)
    Arguments to pass to the remote event.

Return Value

  • Returns true on success or false on an error.

Example

Script on the server:

function OnPlayerJoin(player)
	CallRemoteEvent(player, "ServerCallsMe", 1337, 3.1415, "hello client!")
end
AddEvent("OnPlayerJoin", OnPlayerJoin)

Script on the client:

function ServerCallsMe(arg1, arg2, arg3)
	AddPlayerChat("Server called ServerCallsMe("..arg1..", "..arg2..", "..arg3..")")
end
AddRemoteEvent("ServerCallsMe", ServerCallsMe)

See also