Pool::forEachInRange
Server-Side Function
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
pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction);
Required Arguments
- callingFunction: Function to be executed for each entity within range.
Example
This example collects all vehicles within 100 units of the player and stores them in an array.
Server-Side
let getVehiclesNearby = (player) => {
const nearbyVehicles = [];
mp.vehicles.forEachInRange(player.position, 100, (vehicle) => {
nearbyVehicles.push(vehicle);
});
return nearbyVehicles;
};
let nearbyVehicles = getVehiclesNearby(mp.players.at(0));
console.log(`Vehicles nearby: ${nearbyVehicles.length}`);
See Also
- Functions
- Properties
- Arrays