Pool::length: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This function used for get pool elements count. ==Syntax== <syntaxhighlight lang="javascript"> int pool.length; </syntaxhighlight> ==Example== That's example will return v...")
 
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This function used for get pool elements count.
__NOTOC__
{{SharedJsFunction}}
{{JSContainer|
==Summary==
This property is used to get the element count of a pool.
 
'''Note: this property is read-only.'''
 
{{Pool_list}}


==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">
<pre>
int pool.length;
Number pool.length;
</syntaxhighlight>  
</pre>


==Example==  
==Example==  
That's example will return vehicles and players count.
This example will return the count of vehicles and players, along with the number of "stuff" (if required entities are tracked):


<syntaxhighlight lang="javascript">
{{ServersideCode|
let getStuffCount = () => {
<pre>
return [mp.players.length, mp.vehicles.length];
let getEntityCounts = () => {
    return {
        players: mp.players.length,
        vehicles: mp.vehicles.length,
        objects: mp.objects.length,
        markers: mp.markers.length
    };
};
};


let [players, vehicles] = getStuffCount();
let { players, vehicles, objects, markers } = getEntityCounts();
console.log(`Server have ${vehicles} vehicles and ${players} players.`)
console.log(`The server has ${players} players, ${vehicles} vehicles, ${objects} objects, and ${markers} markers.`);
</syntaxhighlight>
</pre>
}}
}}


==See Also==
==See Also==
{{EntityPool_function}}
{{EntityPool_function}}

Latest revision as of 12:21, 10 November 2024

Shared
Function

 JavaScript


JavaScript Syntax

Summary

This property is used to get the element count of a pool.

Note: this property is read-only.

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

Number pool.length;

Example

This example will return the count of vehicles and players, along with the number of "stuff" (if required entities are tracked):

Server-Side
let getEntityCounts = () => {
    return {
        players: mp.players.length,
        vehicles: mp.vehicles.length,
        objects: mp.objects.length,
        markers: mp.markers.length
    };
};

let { players, vehicles, objects, markers } = getEntityCounts();
console.log(`The server has ${players} players, ${vehicles} vehicles, ${objects} objects, and ${markers} markers.`);


See Also