Pool::forEachInRange: Difference between revisions
No edit summary |
No edit summary |
||
| Line 14: | Line 14: | ||
<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;"> | ||
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div> | <div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div> | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript" highlight="4-8"> | ||
let getVehiclesNearbyMe = (player) => { | let getVehiclesNearbyMe = (player) => { | ||
const returnVehicles = []; | const returnVehicles = []; | ||
Revision as of 15:24, 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