Players::broadcastInRange: Difference between revisions
CocaColaBear (talk | contribs) No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{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"> | ||
mp.players.broadcastInRange(position, range, text [, dimension]); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==Example== | ==Example== | ||
This example sends message to all players | 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; | |||
mp.players.broadcastInRange(pos, 15, `Message from ${player.name}: ${message}`); | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See | }} | ||
==See also== | |||
{{PlayerPool_block}} | {{PlayerPool_block}} | ||
[[Category:Serverside API]] | |||
Latest revision as of 11:07, 10 November 2024
Server-Side Function
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
- Functions
- Players::broadcast
- Players::broadcastInDimension
- Players::broadcastInRange
- Players::call
- Players::callInDimension
- Players::callInRange
- Players::callUnreliable
- Players::callInDimensionUnreliable
- Players::callInRangeUnreliable
- Players::reloadResources
- Pool::apply
- Pool::at
- Pool::exists
- Pool::forEach
- Pool::forEachInDimension
- Pool::forEachInRange
- Pool::getClosest
- Pool::getClosestInDimension
- Pool::toArray
- Pool::toArrayFast