Pool::atHandle: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This function is used to return an element from a pool at an entity handle. ==Syntax== <pre> Entity pool.atHandle(Number handle) </pre> ===Required Arguments=== *'''handle:'...")
 
(Improve again)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
This function is used to return an element from a pool at an entity handle.
Function to get the entity with the given handle from his entity pool.


==Syntax==
==Syntax==
Line 6: Line 6:
</pre>  
</pre>  
===Required Arguments===
===Required Arguments===
*'''handle:''' You can get that for example using entity.handle function.
*'''handle:''' Handle of the entity


===Returns===
===Returns===
*{{RageType|Entity}}
*{{RageType|Entity}} Entity with specified handle, '''undefined''' if none exists.
*'''Note:''' If entity with selected handle does not exist, it will return '''undefined'''.


==Example==  
==Example==  
This example will return a player by '''handle''' and output his name on the chat.
This example will get a player by '''handle''' and output his name on the chat.
{{ClientsideCode|
{{ClientsideCode|
<pre>
<pre>
const player = mp.players.atHandle(mp.players.at(0).handle); // get handle of player with id 0
function outputPlayerNameWithHandle(handle) {
if (player) {
    const player = mp.players.atHandle(handle);
mp.gui.chat.push(`Player with handle: ${localPlayerHandle} is named ${player.name}.`);
    if (player) {
} else {
mp.gui.chat.push(`Player with handle ${handle} is named ${player.name}.`);
mp.gui.chat.push(`Player with handle: ${localPlayerHandle} does not exist.`);
    } else {
mp.gui.chat.push(`Player with handle ${handle} does not exist.`);
    }
}
}
</pre>
</pre>

Latest revision as of 12:53, 4 January 2021

Function to get the entity with the given handle from his entity pool.

Syntax

Entity pool.atHandle(Number handle)

Required Arguments

  • handle: Handle of the entity

Returns

  • Entity Entity with specified handle, undefined if none exists.

Example

This example will get a player by handle and output his name on the chat.

Client-Side
function outputPlayerNameWithHandle(handle) {
    const player = mp.players.atHandle(handle);
    if (player) {
	mp.gui.chat.push(`Player with handle ${handle} is named ${player.name}.`);
    } else {
	mp.gui.chat.push(`Player with handle ${handle} does not exist.`);
    }
}

See Also