TriggerLatentServerEvent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
This function is the same as [[triggerServerEvent]] except the transmission rate of the data contained in the arguments can be limited.
This function is the same as [[triggerServerEvent]] except the transmission rate of the data contained in the arguments can be limited and other network traffic is not blocked while the data is being transferred.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool triggerLatentServerEvent ( string event, [int bandwidth=5000,] [bool persist=false,] element theElement, [arguments...] )
bool triggerLatentServerEvent ( string event, [int bandwidth=5000, bool persist=false,] element theElement, [arguments...] )
</syntaxhighlight>  
</syntaxhighlight>  


Line 15: Line 15:
*'''bandwidth:''' The bytes per second rate to send the data contained in the arguments.
*'''bandwidth:''' The bytes per second rate to send the data contained in the arguments.
*'''persist:''' A bool indicating whether the transmission should be allowed to continue even after the resource that triggered it has since stopped.
*'''persist:''' A bool indicating whether the transmission should be allowed to continue even after the resource that triggered it has since stopped.
*'''arguments...:''' A list of arguments to trigger with the event. You can pass any lua data type (except functions). You can also pass [[element]]s. The total amount of data should not exceed 100MB.  
*'''arguments...:''' A list of arguments to trigger with the event. You can pass any Lua data type (except functions). You can also pass [[element]]s. The total amount of data should not exceed 100MB.  


===Returns===
===Returns===
Line 21: Line 21:


==Example==  
==Example==  
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
  --TODO
if fileExists("text.txt")
file = fileOpen("test.txt") --Open a file (you can create it yourself).
local data = fileRead(file,100*1024*1024) --Max 100 MB
fileClose(file) --Close File
triggerLatentServerEvent("onReadFile",5000,false,root,data) --trigger
end
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
addEvent("onReadFile",true)
addEventHandler("onReadFile",root,function(data)
local file = fileCreate("text.txt") --Save "data" into "text.txt"
fileWrite(file,data)
fileClose(file)
end)


==Requirements==
</syntaxhighlight>
{{Requirements|n/a|1.3.0-9.03772|}}
</section>


==See Also==
==See Also==
{{Client_event_functions}}
{{Client_event_functions}}

Latest revision as of 15:44, 7 November 2024

This function is the same as triggerServerEvent except the transmission rate of the data contained in the arguments can be limited and other network traffic is not blocked while the data is being transferred.

Syntax

bool triggerLatentServerEvent ( string event, [int bandwidth=5000, bool persist=false,] element theElement, [arguments...] )

Required Arguments

  • event: The name of the event to trigger server-side. You should register this event with addEvent and add at least one event handler using addEventHandler.
  • theElement: The element that is the source of the event. This could be another player, or if this isn't relevant, use the root element.

Optional Arguments

  • bandwidth: The bytes per second rate to send the data contained in the arguments.
  • persist: A bool indicating whether the transmission should be allowed to continue even after the resource that triggered it has since stopped.
  • arguments...: A list of arguments to trigger with the event. You can pass any Lua data type (except functions). You can also pass elements. The total amount of data should not exceed 100MB.

Returns

Returns true if the event trigger has been sent, false if invalid arguments were specified.

Example

Click to collapse [-]
Client
if fileExists("text.txt")
	file = fileOpen("test.txt")						--Open a file (you can create it yourself).
	local data = fileRead(file,100*1024*1024)				--Max 100 MB
	fileClose(file)								--Close File
	triggerLatentServerEvent("onReadFile",5000,false,root,data)	--trigger
end
Click to collapse [-]
Server
addEvent("onReadFile",true)
addEventHandler("onReadFile",root,function(data)
	local file = fileCreate("text.txt")					--Save "data" into "text.txt"
	fileWrite(file,data)
	fileClose(file)
end)

See Also