Pool::forEachInRange: Difference between revisions
CocaColaBear (talk | contribs) No edit summary |
(Fixed some English, and fixed example border) |
||
| Line 1: | Line 1: | ||
This function used for | This function is used for calling a function for each element in a pool, but only if it in range of position. | ||
==Syntax== | ==Syntax== | ||
<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> | ||
===Required Arguments=== | ===Required Arguments=== | ||
| Line 13: | Line 10: | ||
==Example #1== | ==Example #1== | ||
That's example will generate array with vehicles | 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
- Functions
- Properties
- Arrays