Pool::forEachInRange: Difference between revisions
(Small fix) |
No edit summary |
||
| Line 3: | Line 3: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 14:51, 26 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
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
- Functions
- Properties
- Arrays