Players::call: Difference between revisions
m (Replaced HTML with template) |
No edit summary |
||
| Line 1: | Line 1: | ||
{{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 "disablePlayerRegeneration" event for | 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) => | const playersArray = mp.players.toArray().filter((player) => | ||
player.dist(new mp.Vector3(150, 100, 50)) < 20 | |||
); | |||
mp.players.call(playersArray, "disablePlayerRegeneration"); | 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"); | mp.players.call("disablePlayerRegeneration"); | ||
</ | </syntaxhighlight> | ||
}} | }} | ||
==See also== | |||
==See | |||
{{Player_block}} | {{Player_block}} | ||
[[Category:Serverside API]] | |||
Latest revision as of 11:09, 10 November 2024
Server-Side Function
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
- Functions
- Player::ban
- Player::call
- Player::callProc
- Player::callToStreamed
- Player::callUnreliable
- Player::cancelPendingRpc
- Player::clearDecorations
- Player::getClothes
- Player::getDecoration
- Player::getFaceFeature
- Player::getHeadBlend
- Player::getHeadOverlay
- Player::getProp
- Player::getWeaponAmmo
- Player::giveWeapon
- Player::hasPendingRpc
- Player::invoke
- Player::isStreamed
- Player::isStreamedFor
- Player::kick
- Player::kickSilent
- Player::notify
- Player::outputChatBox
- Player::playAnimation
- Player::playScenario
- Player::putIntoVehicle
- Player::removeFromVehicle
- Player::removeObject
- Player::removeWeapon
- Player::removeAllWeapons
- Player::resetWeapon
- Player::setClothes
- Player::setCustomization
- Player::setDecoration
- Player::setFaceFeature
- Player::setHairColor
- Player::setHeadBlend
- Player::setHeadOverlay
- Player::setProp
- Player::setWeaponAmmo
- Player::spawn
- Player::stopAnimation
- Player::updateHeadBlend
- Player::enableVoiceTo
- Player::disableVoiceTo
- Weapons::clear
- Entity::destroy
- Entity::dist
- Entity::distSquared
- Entity::getVariable
- Entity::setVariable
- Entity::setVariables
- Properties
- Player::action
- Player::aimTarget
- Player::allWeapons
- Player::armour
- Player::eyeColor
- Player::faceFeatures
- Player::hairColor
- Player::hairHighlightColor
- Player::heading
- Player::health
- Player::rgscId
- Player::ip
- Player::serial
- Player::isAiming
- Player::isClimbing
- Player::isEnteringVehicle
- Player::isInCover
- Player::isInMelee
- Player::isJumping
- Player::isLeavingVehicle
- Player::isOnLadder
- Player::isReloading
- Player::name
- Player::packetLoss
- Player::ping
- Player::seat
- Player::socialClub
- Player::streamedPlayers
- Player::vehicle
- Player::voiceListeners
- Player::disableOutgoingSync
- Player::weapon
- Player::weaponAmmo
- Player::weapons
- Entity::alpha
- Entity::data
- Entity::dimension
- Entity::id
- Entity::model
- Entity::position
- Entity::type