Player::call: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
m (informed anyone reading that you cant pass vector3 type variables through this call)
Line 36: Line 36:
</syntaxhighlight>
</syntaxhighlight>
</div>
</div>
<b> You cannot pass Vector3 types </b> ''(send them through x,y,z and put them in a Vector3 type variable in the client function)''


==See Also==
==See Also==
{{Player_block}}
{{Player_block}}

Revision as of 18:38, 7 January 2018

This function call added client-side event for selected player.

Syntax

player.call(String eventName [, ...args]);

Required Arguments

  • eventName: Event name, what 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

That's example will call event added on client side for player with ID 1337, disable regeneration health and send number current player health.

Client-Side
let disableRegeneration = (currentHealth) => { //currentHealth - value, what we send from server.
	mp.game.player.setHealthRechargeMultiplier(0); //Disable regeneration
	let text = `Regeneration disabled. Current health: ${currentHealth}`;
	mp.gui.chat.push(text); //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);
};


You cannot pass Vector3 types (send them through x,y,z and put them in a Vector3 type variable in the client function)

See Also