Player::callProc: Difference between revisions

From RAGE Multiplayer Wiki
(Add async proc example)
m (Missing `)` in example)
 
Line 25: Line 25:
     console.error('Error: ' + e);
     console.error('Error: ' + e);
   }
   }
}();
})();
</pre>
</pre>
}}
}}

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