Skip to main content

Pool::forEachInRange

Server-side function

Available Entity Pools​

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

Entity PoolDescription
mp.playersManages all connected players
mp.vehiclesManages all spawned vehicles
mp.objectsManages all created objects
mp.pedsManages all non-player characters (peds)
mp.markersManages all markers in the game
mp.labelsManages all 3D text labels
mp.checkpointsManages checkpoints
mp.blipsManages map blips
mp.colshapesManages 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}`);