Players::broadcast: Difference between revisions
(→Syntax) |
No edit summary |
||
| Line 1: | Line 1: | ||
{{ServersideJsFunction}} | |||
{{JSContainer| | |||
==Summary== | |||
The `mp.players.broadcast` function sends a chat message to all connected players on the server. This function is commonly used for global announcements or notifications. | |||
===Required Params=== | |||
*'''text:''' {{RageType|string}} — The message text to broadcast to all players. | |||
===Return value=== | |||
*''' {{RageType|void}} ''' | |||
==Syntax== | ==Syntax== | ||
| Line 5: | Line 15: | ||
mp.players.broadcast(text); | mp.players.broadcast(text); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Example== | ==Example== | ||
This example sends player message to all | This example sends a player's message to all other players. | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
mp.events.addCommand("say", (player, message) => { | mp.events.addCommand("say", (player, message) => { | ||
mp.players.broadcast(`Message from ${player.name}: ${message}`); | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See | }} | ||
==See also== | |||
{{PlayerPool_block}} | {{PlayerPool_block}} | ||
[[Category:Serverside API]] | |||
Latest revision as of 11:05, 10 November 2024
Server-Side Function
JavaScript Syntax
Summary
The `mp.players.broadcast` function sends a chat message to all connected players on the server. This function is commonly used for global announcements or notifications.
Required Params
- text: string — The message text to broadcast to all players.
Return value
- void
Syntax
mp.players.broadcast(text);
Example
This example sends a player's message to all other players.
mp.events.addCommand("say", (player, message) => {
mp.players.broadcast(`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