Pool::forEachInRange: Difference between revisions
(Fixed some English, and fixed example border) |
No edit summary |
||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{ServersideJsFunction}} | |||
{{JSContainer| | |||
{{Pool_list}} | |||
==Syntax== | ==Syntax== | ||
< | <pre> | ||
pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction); | |||
</ | </pre> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''callingFunction:''' Function | *'''callingFunction:''' Function to be executed for each entity within range. | ||
==Example | ==Example== | ||
This example collects all vehicles within 100 units of the player and stores them in an array. | |||
{{ServersideCode| | |||
< | <pre> | ||
let getVehiclesNearby = (player) => { | |||
let | const nearbyVehicles = []; | ||
mp.vehicles.forEachInRange(player.position, 100, (vehicle) => { | |||
nearbyVehicles.push(vehicle); | |||
}); | |||
return nearbyVehicles; | |||
}; | }; | ||
let | let nearbyVehicles = getVehiclesNearby(mp.players.at(0)); | ||
console.log(`Vehicles nearby | console.log(`Vehicles nearby: ${nearbyVehicles.length}`); | ||
</ | </pre> | ||
}} | |||
==See Also== | ==See Also== | ||
{{EntityPool_function}} | {{EntityPool_function}} | ||
}} | |||
Latest revision as of 12:12, 10 November 2024
Server-Side Function
JavaScript Syntax
Available Entity Pools
The following are the main entity pools available on the RAGEMP, used for managing various game entities:
| Entity Pool | Description |
|---|---|
| mp.players | Manages all connected players |
| mp.vehicles | Manages all spawned vehicles |
| mp.objects | Manages all created objects |
| mp.peds | Manages all non-player characters (peds) |
| mp.markers | Manages all markers in the game |
| mp.labels | Manages all 3D text labels |
| mp.checkpoints | Manages checkpoints |
| mp.blips | Manages map blips |
| mp.colshapes | Manages collision shapes |
Syntax
pool.forEachInRange(Vector3 position, int range [, int dimension], function callingFunction);
Required Arguments
- callingFunction: Function to be executed for each entity within range.
Example
This example collects all vehicles within 100 units of the player and stores them in an array.
Server-Side
let getVehiclesNearby = (player) => {
const nearbyVehicles = [];
mp.vehicles.forEachInRange(player.position, 100, (vehicle) => {
nearbyVehicles.push(vehicle);
});
return nearbyVehicles;
};
let nearbyVehicles = getVehiclesNearby(mp.players.at(0));
console.log(`Vehicles nearby: ${nearbyVehicles.length}`);
See Also
- Functions
- Properties
- Arrays