Pool::forEachInRange: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
(Fixed some English, and fixed example border)
Line 1: Line 1:
This function used for call function for each elements in pool, but only if it in range of position.
This function is used for calling a function for each element in a pool, but only if it in range of position.


==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===
Line 13: Line 10:


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


<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">
let getVehiclesNearbyMe = (player) => {
let getVehiclesNearbyMe = (player) => {
Line 31: Line 30:
console.log(`Vehicles nearby me: x${vehiclesNearbyMe.length}`);
console.log(`Vehicles nearby me: x${vehiclesNearbyMe.length}`);
</syntaxhighlight>
</syntaxhighlight>
</div>


==See Also==
==See Also==
{{EntityPool_function}}
{{EntityPool_function}}

Revision as of 10:05, 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 #1

That's example will generate an array with 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