Players::call: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "{{Incomplete Functions}}")
 
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Incomplete Functions}}
{{ServersideJsFunction}}
{{JSContainer|
 
==Summary==
The `mp.players.call` function triggers a specified event on the client-side for either all players or a defined array of players. It is useful for synchronizing client events across multiple players on the server.
 
===Required Params===
*'''eventName:''' {{RageType|string}} — The name of the client event to trigger.
*'''args:''' {{RageType|Array}} — Arguments to send with the event. Supports strings, numbers, booleans, entities; objects and arrays should be in JSON format.
 
===Syntax===
<syntaxhighlight lang="javascript">
mp.players.call(eventName[, args]);
mp.players.call(playersArray, eventName[, args]);
</syntaxhighlight>
 
==Examples==
1. **Trigger an event for nearby players**: This example triggers the `"disablePlayerRegeneration"` event for all players within 20 units of a position `(150, 100, 50)`.
 
<syntaxhighlight lang="javascript">
const playersArray = mp.players.toArray().filter((player) =>
    player.dist(new mp.Vector3(150, 100, 50)) < 20
);
mp.players.call(playersArray, "disablePlayerRegeneration");
</syntaxhighlight>
 
2. **Trigger an event for all players**: This example triggers the `"disablePlayerRegeneration"` event for everyone on the server.
 
<syntaxhighlight lang="javascript">
mp.players.call("disablePlayerRegeneration");
</syntaxhighlight>
 
}}
==See also==
{{Player_block}}
[[Category:Serverside API]]

Latest revision as of 11:09, 10 November 2024

Server-Side
Function

 JavaScript



JavaScript Syntax


Summary

The `mp.players.call` function triggers a specified event on the client-side for either all players or a defined array of players. It is useful for synchronizing client events across multiple players on the server.

Required Params

  • eventName: string — The name of the client event to trigger.
  • args: Array — Arguments to send with the event. Supports strings, numbers, booleans, entities; objects and arrays should be in JSON format.

Syntax

mp.players.call(eventName[, args]);
mp.players.call(playersArray, eventName[, args]);

Examples

1. **Trigger an event for nearby players**: This example triggers the `"disablePlayerRegeneration"` event for all players within 20 units of a position `(150, 100, 50)`.

const playersArray = mp.players.toArray().filter((player) => 
    player.dist(new mp.Vector3(150, 100, 50)) < 20
);
mp.players.call(playersArray, "disablePlayerRegeneration");

2. **Trigger an event for all players**: This example triggers the `"disablePlayerRegeneration"` event for everyone on the server.

mp.players.call("disablePlayerRegeneration");



See also