Player::callProc: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "__TOC__ {{ServersideJsFunction}} This function calls the specified player's clientside and expects a callback. {{JSContainer| ==Syntax== <pre> player.callProc('eventProcNam...")
 
m (Missing `)` in example)
 
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
{{ServersideJsFunction}}
{{ServersideJsFunction}}


This function calls the specified player's clientside and expects a callback.
This function calls the specified player's clientside Remote prodecure call (RPC) event and expects a callback.


{{JSContainer|
{{JSContainer|
Line 25: Line 25:
     console.error('Error: ' + e);
     console.error('Error: ' + e);
   }
   }
}();
})();
</pre>
</pre>
}}
}}
Line 33: Line 33:
<pre>
<pre>
mp.events.addProc('test_proc', (player, text) => {
mp.events.addProc('test_proc', (player, text) => {
  return 'hey beast: ' + text;
});
// also supports async functions
mp.events.addProc('test_proc', async (text) => {
  await doAsyncJob();
   return 'hey beast: ' + text;
   return 'hey beast: ' + text;
});
});
Line 38: Line 44:
}}
}}
}}
}}
==See Also==
{{Player_block}}

Latest revision as of 07:53, 4 July 2020

Server-Side
Function

 JavaScript



This function calls the specified player's clientside Remote prodecure call (RPC) event and expects a callback.

JavaScript Syntax

Syntax

player.callProc('eventProcName', [...args]);

Required Arguments

  • *eventProcName: String
  • args: Any

Example

Server-Side
(async () => {
  try {
     let res = await player.callProc('test_proc', ['ok']);
     console.log('succ', res);
  } catch(e) {
    console.error('Error: ' + e);
  }
})();


Client-Side
mp.events.addProc('test_proc', (player, text) => {
  return 'hey beast: ' + text;
});

// also supports async functions
mp.events.addProc('test_proc', async (text) => {
  await doAsyncJob();
  return 'hey beast: ' + text;
});


See Also