Pool::forEachInRange: Difference between revisions

From RAGE Multiplayer Wiki
(Fixed some English, and fixed example border)
(Small fix)
Line 9: Line 9:
*'''callingFunction:''' Function, what will be called.
*'''callingFunction:''' Function, what will be called.


==Example #1==  
==Example==  
That's example will generate an array with vehicles within 100 units of the player (game distance, meters).
This example will generate an array of vehicles within 100 units of the player (game distance, meters).


<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">

Revision as of 10:06, 20 September 2017

This function is used for calling a function for each element in a 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

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