Pool::forEachInRange: Difference between revisions

From RAGE Multiplayer Wiki
(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...")
 
No edit summary
Line 2: Line 2:


==Syntax==
==Syntax==
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
void pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction);
void pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction);
</syntaxhighlight>  
</syntaxhighlight>
</div>
 
===Required Arguments===
===Required Arguments===
*'''callingFunction:''' Function, what will be called.
*'''callingFunction:''' Function, what will be called.

Revision as of 12:19, 17 September 2017

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

Syntax

Server-Side
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