Difference between revisions of "Events::addProc"

From RAGE Multiplayer Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 
{{Shared}}
 
{{Shared}}
mp.events.addProc register a RPC event into server-side/client-side.
+
<br/>
 +
This function register the specified player's Remote Prodecure Call (RPC) event and expects a callback.
 +
__TOC__
 +
<br/>
  
 +
{{JSContainer|
 
== Syntax ==
 
== Syntax ==
 
 
<pre>
 
<pre>
mp.events.addProc(name[, args], callback);
+
mp.events.addProc('eventProcName', callback);
 
</pre>
 
</pre>
 +
 +
=== Required Arguments ===
 +
*{{Required}}'''eventProcName''': {{RageType|String}}
 +
*{{Required}}'''callback''': {{RageType|Any}}
  
 
== Examples ==
 
== Examples ==
Line 12: Line 19:
 
{{ServersideCode|
 
{{ServersideCode|
 
<pre>
 
<pre>
 +
// register RPC 'test_proc' in server-side
 
mp.events.addProc('test_proc', (player, text) => {
 
mp.events.addProc('test_proc', (player, text) => {
 
   return 'hey beast: ' + text;
 
   return 'hey beast: ' + text;
Line 21: Line 29:
 
<pre>
 
<pre>
 
const response = await mp.events.callRemoteProc('test_proc', 'test');
 
const response = await mp.events.callRemoteProc('test_proc', 'test');
 +
// calls RPC 'test_proc' from server side and wait for result
 
mp.gui.chat.push(`response: ${response}`);
 
mp.gui.chat.push(`response: ${response}`);
 
</pre>
 
</pre>
 +
}}
 
}}
 
}}

Latest revision as of 11:34, 25 June 2020

Shared


This function register the specified player's Remote Prodecure Call (RPC) event and expects a callback.


JavaScript Syntax
Jslogo.png

Syntax

mp.events.addProc('eventProcName', callback);

Required Arguments

  • *eventProcName: String
  • *callback: Any

Examples

Server-Side
// register RPC 'test_proc' in server-side
mp.events.addProc('test_proc', (player, text) => {
  return 'hey beast: ' + text;
});


Client-Side
const response = await mp.events.callRemoteProc('test_proc', 'test');
// calls RPC 'test_proc' from server side and wait for result
mp.gui.chat.push(`response: ${response}`);