Players::broadcastInRange: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
Line 1: Line 1:
This function writes a chat message for all players in range (like [[Player::outputChatBox]]).
{{ServersideJsFunction}}
{{JSContainer|
 
==Summary==
The `mp.players.broadcastInRange` function allows sending a chat message to all players within a specified range from a position. This is useful for proximity-based messaging, where only nearby players will receive the message.
 
===Required Params===
*'''position:''' {{RageType|Vector3}} — The position from which the message is sent.
*'''range:''' {{RageType|number}} — The radius around the position for the message range.
*'''text:''' {{RageType|string}} — The message text to be broadcast.
 
===Optional Params===
*'''dimension:''' {{RageType|number}} — The dimension where the message is sent (default is all dimensions).
 
===Return value===
*''' {{RageType|void}} '''


==Syntax==
==Syntax==
<syntaxhighlight lang="typescript">
<syntaxhighlight lang="typescript">
void players.broadcastInRange(Vecto3 position, number range [, number dimension], string text);
mp.players.broadcastInRange(position, range, text [, dimension]);
</syntaxhighlight>  
</syntaxhighlight>
===Required Arguments===
*'''position:''' The position from which the broadcast will be sent.
*'''range:''' The range from position.
*'''text:''' The text to be sent.
 
===Optional Arguments===
*'''dimension:''' The dimension in which the broadcast will be sent.


==Example==
==Example==
This example sends message to all players in 15 units from the player
This example sends a message to all players within 15 units of the player.
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
mp.events.addCommand("say", (player, message) => {
mp.events.addCommand("say", (player, message) => {
let pos = player.position;
    let pos = player.position;
 
    mp.players.broadcastInRange(pos, 15, `Message from ${player.name}: ${message}`);
mp.players.broadcastInRange(pos, 15, `Message from ${player.name}: ${message}`);
 
});
});
</syntaxhighlight>
</syntaxhighlight>


==See Also==
}}
==See also==
{{PlayerPool_block}}
{{PlayerPool_block}}
[[Category:Serverside API]]

Latest revision as of 11:07, 10 November 2024

Server-Side
Function

 JavaScript



JavaScript Syntax


Summary

The `mp.players.broadcastInRange` function allows sending a chat message to all players within a specified range from a position. This is useful for proximity-based messaging, where only nearby players will receive the message.

Required Params

  • position: Vector3 — The position from which the message is sent.
  • range: number — The radius around the position for the message range.
  • text: string — The message text to be broadcast.

Optional Params

  • dimension: number — The dimension where the message is sent (default is all dimensions).

Return value

  • void

Syntax

mp.players.broadcastInRange(position, range, text [, dimension]);

Example

This example sends a message to all players within 15 units of the player.

mp.events.addCommand("say", (player, message) => {
    let pos = player.position;
    mp.players.broadcastInRange(pos, 15, `Message from ${player.name}: ${message}`);
});



See also