nearestLocations: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<code>([^<]*)\[\[([a-zA-Z][a-zA-Z0-9_]+)\]\]([^<]*)<\/code>" to "<code>$1$2$3</code>")
m (Some wiki formatting)
 
(4 intermediate revisions by 3 users not shown)
Line 19: Line 19:


|descr= Returns an array of locations of chosen type(s) within the given radius of the given position, sorted from nearest to farthest.
|descr= Returns an array of locations of chosen type(s) within the given radius of the given position, sorted from nearest to farthest.
{{Feature | Informative | Although locations can be placed in 3D with [[setPosition]], [[nearestLocations]] search result is sorted in 2D.}}
{{Feature|informative|Although locations can be placed in 3D with [[setPosition]], [[nearestLocations]]' search result is sorted in 2D.}}


|s1= [[nearestLocations]] [position, [locationType1, locationType2, ...], radius, sortPosition]
|s1= [[nearestLocations]] [centre, locationTypes, radius, sortPosition]


|p1= position: [[Array]] - [[Position#Introduction|Position2D]], [[Position#Introduction|Position3D]] or [[Object]]
|p1= centre: [[Array]] format [[Position#Introduction|Position2D]], [[Position#Introduction|Position3D]] or [[Object]]


|p2= locationTypeX: [[String]] - [[Location#Location Types|location type]] name, e.g "NameCity"
|p2= locationTypes: [[Array]] of [[String]]s - list of [[Location#Location Types|location type]] names, e.g "NameCity"; {{GVI|arma3|2.14|size= 0.75}} passing empty array [] will return all available locations within the radius


|p3= radius: [[Number]] - maximum distance from the given position that returned locations may be, in meters.
|p3= radius: [[Number]] - maximum distance from the given position that returned locations may be, in metres


|p4= sortPosition: [[Array]] - (Optional) [[Position#Introduction|Position2D]], [[Position#Introduction|Position3D]] or [[Object]] - results will be sorted from the distance to given ''sortPosition'' (nearest to farthest still)
|p4= sortPosition: [[Array]] format [[Position#Introduction|Position2D]], [[Position#Introduction|Position3D]] or [[Object]] - (Optional) results will be sorted from the distance to given ''sortPosition'' (nearest to farthest still)


|r1= [[Array]] of [[Location|locations]]
|r1= [[Array]] of [[Location]]s


|x1= <code>_nearbyLocations = nearestLocations [position player, ["RockArea", "VegetationFir"], 100];</code>
|x1= <sqf>_nearbyLocations = nearestLocations [getPosATL player, ["RockArea", "VegetationFir"], 100];</sqf>


|x2= Find any of nearest locations:
|x2= Find any of nearest locations:
<code>private _allLocationTypes = [];
<sqf>
private _allLocationTypes = [];
"_allLocationTypes pushBack configName _x" configClasses (configFile >> "CfgLocationTypes");
"_allLocationTypes pushBack configName _x" configClasses (configFile >> "CfgLocationTypes");
{
{
Line 43: Line 44:
_x,  
_x,  
text _x,  
text _x,  
position player distance _x
getPosATL player distance _x
];
];
} forEach nearestLocations [player, _allLocationTypes, 500];</code>
} forEach nearestLocations [player, _allLocationTypes, 500];
</sqf>


|seealso= [[createLocation]] [[nearestLocation]] [[locationPosition]] [[nearestLocationWithDubbing]]
|seealso= [[createLocation]] [[nearestLocation]] [[locationPosition]] [[nearestLocationWithDubbing]]
}}
}}

Latest revision as of 01:20, 6 September 2023

Hover & click on the images for description

Description

Description:
Returns an array of locations of chosen type(s) within the given radius of the given position, sorted from nearest to farthest.
Although locations can be placed in 3D with setPosition, nearestLocations' search result is sorted in 2D.
Groups:
Locations

Syntax

Syntax:
nearestLocations [centre, locationTypes, radius, sortPosition]
Parameters:
centre: Array format Position2D, Position3D or Object
locationTypes: Array of Strings - list of location type names, e.g "NameCity"; Arma 3 logo black.png2.14 passing empty array [] will return all available locations within the radius
radius: Number - maximum distance from the given position that returned locations may be, in metres
sortPosition: Array format Position2D, Position3D or Object - (Optional) results will be sorted from the distance to given sortPosition (nearest to farthest still)
Return Value:
Array of Locations

Examples

Example 1:
_nearbyLocations = nearestLocations [getPosATL player, ["RockArea", "VegetationFir"], 100];
Example 2:
Find any of nearest locations:
private _allLocationTypes = []; "_allLocationTypes pushBack configName _x" configClasses (configFile >> "CfgLocationTypes"); { systemChat format [ "%1 (%2) - %3m", _x, text _x, getPosATL player distance _x ]; } forEach nearestLocations [player, _allLocationTypes, 500];

Additional Information

See also:
createLocation nearestLocation locationPosition nearestLocationWithDubbing

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note