CallRemoteEvent: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|CallRemoteEvent(player, EventName [, UserArgs])}} {{FuncParameters}} {{FuncParam|player|__EDIT_ME_..."
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server & Client|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|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.<br>Remote events are independent of packages meaning you can call remote events across different packages.}}


{{FuncSyntax|CallRemoteEvent(player, EventName [, UserArgs])}}
====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
 
{{FuncSyntax|CallRemoteEvent(player, EventName [, LuaArgs...])}}
{{FuncSyntaxClient|CallRemoteEvent(EventName [, LuaArgs...])}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|player|__EDIT_ME__}}
{{FuncParam|player|The player identifier to call a remote event.}}
{{FuncParam|EventName |__EDIT_ME__}}
{{FuncParam|EventName|The name of the remote event as a string which was explicit defined by [[AddRemoteEvent]].}}
{{FuncParamOptional|UserArgs|__EDIT_ME__}}
{{FuncParamOptional|UserArgs|Arguments to pass to the remote event.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns '''true''' on success or '''false''' on an error.}}


== Example ==
== Example ==
__EDIT_ME__
Script on the server:
<syntaxhighlight lang="Lua">
function OnPlayerJoin(player)
CallRemoteEvent(player, "ServerCallsMe", 1337, 3.1415, "hello client!")
end
AddEvent("OnPlayerJoin", OnPlayerJoin)
</syntaxhighlight>
 
Script on the client:
<syntaxhighlight lang="Lua">
function ServerCallsMe(arg1, arg2, arg3)
AddPlayerChat("Server called ServerCallsMe("..arg1..", "..arg2..", "..arg3..")")
end
AddRemoteEvent("ServerCallsMe", ServerCallsMe)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
* [[AddEvent]]
* [[CallEvent]]
* [[AddRemoteEvent]]
* [[CallRemoteEvent]]
* [[BroadcastRemoteEvent]]
* [[AddCommand]]
* [[GetAllPackages]]

Latest revision as of 17:05, 30 December 2020

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