Pool::forEachInRange: Difference between revisions
No edit summary |
m (Replaced HTML with template) |
||
| Line 2: | Line 2: | ||
==Syntax== | ==Syntax== | ||
< | <pre> | ||
pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction); | pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction); | ||
</ | </pre> | ||
===Required Arguments=== | ===Required Arguments=== | ||
| Line 12: | Line 12: | ||
This example will generate an array of 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). | ||
{{ServersideCode| | |||
<pre> | |||
< | |||
let getVehiclesNearbyMe = (player) => { | let getVehiclesNearbyMe = (player) => { | ||
const returnVehicles = []; | const returnVehicles = []; | ||
| Line 29: | Line 28: | ||
let vehiclesNearbyMe = getVehiclesNearbyMe(mp.players.at(0)); | let vehiclesNearbyMe = getVehiclesNearbyMe(mp.players.at(0)); | ||
console.log(`Vehicles nearby me: x${vehiclesNearbyMe.length}`); | console.log(`Vehicles nearby me: x${vehiclesNearbyMe.length}`); | ||
</ | </pre> | ||
}} | |||
==See Also== | ==See Also== | ||
{{EntityPool_function}} | {{EntityPool_function}} | ||
Revision as of 11:23, 26 October 2018
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