Pool::at: Difference between revisions

From RAGE Multiplayer Wiki
m (Another grammatical error was fixed.)
No edit summary
Line 1: Line 1:
This function is used to return an element from a pool at an ID.
{{ServersideJsFunction}}
{{JSContainer|


==Syntax==
==Available Entity Pools==
<pre>
In RAGEMP serverside JavaScript, the following entity pools are used to manage different in-game elements:
Entity pool.at(Number ID)
* '''mp.players''' — Manages all player entities.
</pre>  
* '''mp.vehicles''' — Manages all vehicle entities.
===Returns===
* '''mp.objects''' — Manages all world object entities.
An entity with the selected ID from a pool, or undefined if entity with this ID does not exists.
* '''mp.colshapes''' — Manages all collision shapes.
* '''mp.markers''' — Manages all map markers.
* '''mp.checkpoints''' — Manages all checkpoints.
* '''mp.labels''' — Manages all text labels.
* '''mp.blips''' — Manages all map blips.
* '''mp.pickups''' — Manages item pickups in the world.
 
==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">
pool.at(id)
</syntaxhighlight>
 
===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==
{{ServersideCode|
This example retrieves a player by ID and outputs their name to the console if they exist.
<pre>
 
<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 with id 1488 does not exist...`);
    console.log(`Player with ID 1488 does not exist...`);
};
}
</pre>
</syntaxhighlight>
 
}}
}}
==See Also==
==See Also==
{{EntityPool_function}}
{{EntityPool_function}}
[[Category:Serverside API]]

Revision as of 11:31, 10 November 2024

Server-Side
Function

 JavaScript



JavaScript Syntax


Available Entity Pools

In RAGEMP serverside JavaScript, the following entity pools are used to manage different in-game elements:

  • mp.players — Manages all player entities.
  • mp.vehicles — Manages all vehicle entities.
  • mp.objects — Manages all world object entities.
  • mp.colshapes — Manages all collision shapes.
  • mp.markers — Manages all map markers.
  • mp.checkpoints — Manages all checkpoints.
  • mp.labels — Manages all text labels.
  • mp.blips — Manages all map blips.
  • mp.pickups — Manages item pickups in the world.

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