Player::call: Difference between revisions
MrPancakers (talk | contribs) m (Reworded description and example) |
m (Replaced HTML with template) |
||
| Line 2: | Line 2: | ||
==Syntax== | ==Syntax== | ||
< | <pre> | ||
player.call(String eventName [, ...args]); | player.call(String eventName [, ...args]); | ||
</ | </pre> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''eventName:''' The event name that will be called | *'''eventName:''' The event name that will be called | ||
| Line 12: | Line 12: | ||
This example will call the client-side event 'disablePlayerRegeneration' for the player with the ID 1337. | This example will call the client-side event 'disablePlayerRegeneration' for the player with the ID 1337. | ||
{{ClientsideCode| | |||
<pre> | <pre> | ||
let disableRegeneration = (currentHealth) => { //currentHealth - value, what we send from server. | let disableRegeneration = (currentHealth) => { //currentHealth - value, what we send from server. | ||
| Line 22: | Line 21: | ||
mp.events.add('disablePlayerRegeneration', disableRegeneration); | mp.events.add('disablePlayerRegeneration', disableRegeneration); | ||
</pre> | </pre> | ||
}} | |||
{{ServersideCode| | |||
<pre> | <pre> | ||
let player = mp.player.at(1337); //Get player by ID | let player = mp.player.at(1337); //Get player by ID | ||
| Line 34: | Line 32: | ||
}; | }; | ||
</pre> | </pre> | ||
}} | |||
==See Also== | ==See Also== | ||
{{Player_block}} | {{Player_block}} | ||
Revision as of 11:47, 26 October 2018
This function calls a client-side event for the selected player.
Syntax
player.call(String eventName [, ...args]);
Required Arguments
- eventName: The event name that will be called
- args: Any arguments, what should be sended to client. Supports entities, strings, numbers and booleans. (Objects and Arrays should be packed to JSON format.)
Example
This example will call the client-side event 'disablePlayerRegeneration' for the player with the ID 1337.
Client-Side
let disableRegeneration = (currentHealth) => { //currentHealth - value, what we send from server.
mp.game.player.setHealthRechargeMultiplier(0); //Disable regeneration
mp.gui.chat.push(`Regeneration disabled. Current health: ${currentHealth}`); //Output text to default chatbox
};
mp.events.add('disablePlayerRegeneration', disableRegeneration);
Server-Side
let player = mp.player.at(1337); //Get player by ID
if (player) {
let playerHealth = player.health;
player.call(`disablePlayerRegeneration`, [playerHealth]);
};
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