Pool::toArray: Difference between revisions
MrPancakers2 (talk | contribs) No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{SharedJsFunction}} | {{SharedJsFunction}} | ||
This function converts a pool to an array. If you | This function converts a pool to an array. If you don’t need to create a new array each time, use [[Pool::toArrayFast]] for optimized performance. | ||
{{JSContainer| | {{JSContainer| | ||
{{Pool_list}} | |||
==Syntax== | ==Syntax== | ||
<pre> | <pre> | ||
mp.pool.toArray(); | mp.pool.toArray(); | ||
</pre> | </pre> | ||
==Example== | ==Example== | ||
| Line 14: | Line 17: | ||
<pre> | <pre> | ||
const onlinePlayers = mp.players.toArray(); | const onlinePlayers = mp.players.toArray(); | ||
if(onlinePlayers.every | if (onlinePlayers.every(player => player.isAiming)) { | ||
console.log("Everyone is aiming."); | console.log("Everyone is aiming."); | ||
} | |||
</pre> | </pre> | ||
}} | }} | ||
Revision as of 12:15, 10 November 2024
This function converts a pool to an array. If you don’t need to create a new array each time, use Pool::toArrayFast for optimized performance.
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 |
Syntax
mp.pool.toArray();
Example
Server-Side
const onlinePlayers = mp.players.toArray();
if (onlinePlayers.every(player => player.isAiming)) {
console.log("Everyone is aiming.");
}