Pool::forEachInRange

From RAGE Multiplayer Wiki
Revision as of 11:23, 26 October 2018 by Rootcause (talk | contribs) (Replaced HTML with template)

This function is used for calling a function for each element in a pool, but only if it in range of position.

Syntax

pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction);

Required Arguments

  • callingFunction: Function, what will be called.

Example

This example will generate an array of vehicles within 100 units of the player (game distance, meters).

Server-Side
let getVehiclesNearbyMe = (player) => {
	const returnVehicles = [];
	
	mp.vehicles.forEachInRange(player.position, 100,
		(vehicle) => {
			returnVehicles.push(vehicle);
		}
	);
	
	return returnVehicles;
};

let vehiclesNearbyMe = getVehiclesNearbyMe(mp.players.at(0));
console.log(`Vehicles nearby me: x${vehiclesNearbyMe.length}`);

See Also