Player::call

From RAGE Multiplayer Wiki
Revision as of 11:47, 26 October 2018 by Rootcause (talk | contribs) (Replaced HTML with template)

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