Pool::forEachInRange

From RAGE Multiplayer Wiki
Revision as of 11:10, 16 September 2017 by SalwadoR (talk | contribs) (Created page with "This function used for call function for each elements in pool, but only if it in range of position. ==Syntax== <syntaxhighlight lang="javascript"> void pool.forEachInRange(V...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function used for call function for each elements in pool, but only if it in range of position.

Syntax

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

Required Arguments

  • callingFunction: Function, what will be called.

Example #1

That's example will generate array with vehicles nearby player in 100 units (game distance, like a meters).

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