Pool::at: Difference between revisions

From RAGE Multiplayer Wiki
(Pool list)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This function is used to return an element from a pool at an ID.
{{ServersideJsFunction}}
{{JSContainer|


==Syntax==
{{Pool_list}}
 
==Summary==
The `pool.at` function returns an entity from a specified pool by its ID. It is useful for accessing specific entities such as players, vehicles, or objects by their unique server-side ID.
 
===Syntax===
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Entity pool.at(Number ID)
pool.at(id)
</syntaxhighlight>  
</syntaxhighlight>
===Returns===
 
An entity with the selected ID from a pool, or false if entity with this ID does not exists.
===Return value===
An entity with the selected ID from a pool, or `undefined` if no entity exists with that ID.


===Required Arguments===
===Required Arguments===
*'''ID:''' Element ID, what you need get from the pool.
*'''id:''' {{RageType|Number}} — The ID of the element to retrieve from the pool.
==Example==  
 
This example will return a player by ID and output his name in the console.
==Example==
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
This example retrieves a player by ID and outputs their name to the console if they exist.
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
 
<syntaxhighlight lang="javascript" highlight="1">
<syntaxhighlight lang="javascript">
let player = mp.players.at(1488);
let player = mp.players.at(1488);
if (player) {
if (player) {
console.log(`Player with id 1488 have nickname ${player.name}`);
    console.log(`Player with ID 1488 has nickname ${player.name}`);
} else {
} else {
console.log(`Player by id 1488 does not exists...`);
    console.log(`Player with ID 1488 does not exist...`);
};
}
</syntaxhighlight>
</syntaxhighlight>
</div>


}}
==See Also==
==See Also==
{{EntityPool_function}}
{{EntityPool_function}}
[[Category:Serverside API]]

Latest revision as of 12:07, 10 November 2024

Server-Side
Function

 JavaScript



JavaScript Syntax


Available Entity Pools

The following are the main entity pools available on the RAGEMP, used for managing various game entities:

Entity Pool Description
mp.players Manages all connected players
mp.vehicles Manages all spawned vehicles
mp.objects Manages all created objects
mp.peds Manages all non-player characters (peds)
mp.markers Manages all markers in the game
mp.labels Manages all 3D text labels
mp.checkpoints Manages checkpoints
mp.blips Manages map blips
mp.colshapes Manages collision shapes

Summary

The `pool.at` function returns an entity from a specified pool by its ID. It is useful for accessing specific entities such as players, vehicles, or objects by their unique server-side ID.

Syntax

pool.at(id)

Return value

An entity with the selected ID from a pool, or `undefined` if no entity exists with that ID.

Required Arguments

  • id: Number — The ID of the element to retrieve from the pool.

Example

This example retrieves a player by ID and outputs their name to the console if they exist.

let player = mp.players.at(1488);
if (player) {
    console.log(`Player with ID 1488 has nickname ${player.name}`);
} else {
    console.log(`Player with ID 1488 does not exist...`);
}



See Also