nearEntities: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
(redundant information that the right hand parameter is an array)
(46 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma2 |= Game name
|game1= arma2
|version1= 1.00


|1.00|= Game version
|game2= arma2oa
|version2= 1.50


|arg= global |= Arguments in MP
|game3= tkoh
____________________________________________________________________________________________
|version3= 1.00


| Find entities in the circle with given radius. If typeName(s) is (are) given, only entities of given type (or its subtype) are listed.
|game4= arma3
|version4= 0.50


This command returns only alive entities. If you need to return dead entities as well use [[entities]] command. |= Description
|arg= global
____________________________________________________________________________________________


| position '''nearEntities''' radius |= Syntax
|gr1= Object Detection


|p1= position: [[Object]] or [[Array]] (format [[Position]]) - center of the circle |= PARAMETER1
|descr= [[Image:sphere_radius.jpg|right|200px]]
Finds entities inside a sphere with the given radius. If the alternative syntax is used, only entities of given types or subtypes are listed. Entities returned are not sorted by distance. This command doesn't return dead entities or entities inside vehicles. If you need to return those, use [[entities]] command.{{Feature|Informative|This command is much [[Code_Optimisation#nearEntities_and_nearestObjects | faster]] than [[nearestObjects]] for on-foot soldier and vehicle detection.}}


|p2= radius: [[Number]] - radius of the circle |= PARAMETER2
|s1= position [[nearEntities]] radius


| [[Array]] of [[Object|Objects]]|= RETURNVALUE
|p1= position: [[Object]] or [[Array]] in format [[PositionAGL]] or [[Position2D]] - center of the sphere
____________________________________________________________________________________________


|s2= position '''nearEntities''' [typeName, radius] |=
|p2= radius: [[Number]] - radius of the sphere


|p21= position: [[Object]] or [[Array]] (format [[Position]]) - center of the circle |= PARAMETER1
|r1= [[Array]] of [[Object|Objects]] - not sorted


|p22= [typeName, radius]: [[Array]] |= PARAMETER2
|s2= position [[nearEntities]] [type, radius]


|p23= typeName: [[String]] or [[Array]] of [[String|Strings]] - typeName(s) to search for |= PARAMETER3
|p21= position: [[Object]] or [[Array]] in format [[PositionAGL]] or [[Position2D]] - center of the sphere


|p24= radius: [[Number]] - radius of the circle |= PARAMETER4
|p22= type: [[String]] or [[Array]] of [[String|Strings]] - type(s) to search for


|r2= [[Array]] of [[Object|Objects]] |= RETURNVALUE
|p23= radius: [[Number]] - radius of the sphere
____________________________________________________________________________________________
 
|r2= [[Array]] of [[Object|Objects]] - not sorted
|x1= <code>_list = [[player]] [[nearEntities]] 20;
|x1= <code>_list = [[player]] [[nearEntities]] 20;
_list = ([[position]] [[player]]) [[nearEntities]] 50;
_list = [[ASLToAGL]] [[getPosASL]] [[player]] [[nearEntities]] 50;
_list = [[player]] [[nearEntities]] ["Man", 1000];
_list = [[player]] [[nearEntities]] ["Man", 1000];
_list = ([[position]] [[player]]) [[nearEntities]] ["LaserTarget", 3000];
_list = [[ASLToAGL]] [[getPosASL]] [[player]] [[nearEntities]] ["LaserTarget", 3000];
_list = [[player]] [[nearEntities]] <nowiki>[</nowiki>["Car", "Motorcycle", "Tank"], 50];
_list = [[player]] [[nearEntities]] [<nowiki/>["Car", "Motorcycle", "Tank"], 50];
_list = ([[position]] [[player]]) [[nearEntities]] <nowiki>[</nowiki>["Man", "Air", "Car", "Motorcycle", "Tank"], 200];
_list = [[ASLToAGL]] [[getPosASL]] [[player]] [[nearEntities]] [<nowiki/>["Man", "Air", "Car", "Motorcycle", "Tank"], 200];
</code>|= EXAMPLE1
</code>


____________________________________________________________________________________________
|seealso= [[entities]], [[findNearestEnemy]], [[nearestBuilding]], [[nearestObject]], [[nearestObjects]], [[nearObjects]], [[nearestLocation]], [[nearTargets]], [[nearSupplies]], [[nearestLocationWithDubbing]], [[nearObjectsReady]], [[nearRoads]]
 
| [[findNearestEnemy]], [[nearestBuilding]], [[nearestObject]], [[nearestObjects]], [[nearObjects]], [[nearestLocation]], [[nearTargets]], [[nearSupplies]], [[nearestLocationWithDubbing]], [[nearObjectsReady]], [[nearRoads]] |= SEEALSO
 
|  |= MPBEHAVIOUR
____________________________________________________________________________________________
}}
}}
<h3 style='display:none'>Notes</h3>
<dl class='command_description'>
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 27 Mar, 2014
<dt class="note">'''[[User:Floriangeyer|Floriangeyer]]'''<dd class="note">
According to [[Code Optimisation]], this function is the fastest and should be used instead of [[nearestObjects]].
<!-- Note Section END -->
</dl>
<h3 style='display:none'>Bottom Section</h3>
[[Category:ArmA 2: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on February 3, 2015 - 21:30 (UTC)</dd>
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
<dd class="note">
This kind of functions remains FPS killer if you can't manage conditions in order to reduce operations for each entity or, to reduce the number of entities.
One of the most demanding CPU/GPU resource is probably a DrawIcon3D treatment for these entities.
Don't stay with a simple radius condition (disk selecting entities).
Each time you can treat visible entities, as icons displaying, try to restrict this function to your screen.
For example: 
if (((worldToScreen (visiblePosition _x)) select 0 > (0 * safezoneW + safezoneX)) &&
((worldToScreen (visiblePosition _x)) select 0 <(1 * safezoneW + safezoneX))) then {...} foreach _pos nearEntities _radius
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 13:26, 16 October 2021

Hover & click on the images for description

Description

Description:
sphere radius.jpg
Finds entities inside a sphere with the given radius. If the alternative syntax is used, only entities of given types or subtypes are listed. Entities returned are not sorted by distance. This command doesn't return dead entities or entities inside vehicles. If you need to return those, use entities command.
This command is much faster than nearestObjects for on-foot soldier and vehicle detection.
Groups:
Object Detection

Syntax

Syntax:
position nearEntities radius
Parameters:
position: Object or Array in format PositionAGL or Position2D - center of the sphere
radius: Number - radius of the sphere
Return Value:
Array of Objects - not sorted

Alternative Syntax

Syntax:
position nearEntities [type, radius]
Parameters:
position: Object or Array in format PositionAGL or Position2D - center of the sphere
type: String or Array of Strings - type(s) to search for
radius: Number - radius of the sphere
Return Value:
Array of Objects - not sorted

Examples

Example 1:
_list = player nearEntities 20; _list = ASLToAGL getPosASL player nearEntities 50; _list = player nearEntities ["Man", 1000]; _list = ASLToAGL getPosASL player nearEntities ["LaserTarget", 3000]; _list = player nearEntities [["Car", "Motorcycle", "Tank"], 50]; _list = ASLToAGL getPosASL player nearEntities [["Man", "Air", "Car", "Motorcycle", "Tank"], 200];

Additional Information

See also:
entitiesfindNearestEnemynearestBuildingnearestObjectnearestObjectsnearObjectsnearestLocationnearTargetsnearSuppliesnearestLocationWithDubbingnearObjectsReadynearRoads

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