nearestTerrainObjects: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "|= Game name" to "|Game name=")
Line 9: Line 9:
| Returns a list of nearest terrain objects of the given types to the given position or object, within the specified distance. If more than one object is found they will be ordered according to 3D distance to the object (i.e. the closest one will be first in the array).  
| Returns a list of nearest terrain objects of the given types to the given position or object, within the specified distance. If more than one object is found they will be ordered according to 3D distance to the object (i.e. the closest one will be first in the array).  
In contrast to [[nearestObjects]] this command returns terrain placed objects like trees, rocks and buildings which don't necessarily need an associated config class.<br><br>
In contrast to [[nearestObjects]] this command returns terrain placed objects like trees, rocks and buildings which don't necessarily need an associated config class.<br><br>
''position'' can use the format:
<tt><nowiki>[[</nowiki>x,y,z], ["Type",...], radius]</tt>
or
<tt>[object, ["Type",...], radius]</tt>
To use it without any type filter:
<tt>[object or position, [], radius]</tt>
<br>
<br>
Possible type names:<tt>"TREE", "SMALL TREE", "BUSH", "BUILDING", "HOUSE", "FOREST BORDER", "FOREST TRIANGLE", "FOREST SQUARE", "CHURCH", "CHAPEL", "CROSS", "BUNKER", "FORTRESS", "FOUNTAIN", "VIEW-TOWER", "LIGHTHOUSE", "QUAY", "FUELSTATION", "HOSPITAL", "FENCE", "WALL", "HIDE", "BUSSTOP", "ROAD", "FOREST", "TRANSMITTER", "STACK", "RUIN", "TOURISM", "WATERTOWER", "TRACK", "MAIN ROAD", "ROCK", "ROCKS", "POWER LINES", "RAILWAY", "POWERSOLAR", "POWERWAVE", "POWERWIND", "SHIPWRECK", "TRAIL"</tt>
Possible type names:<tt>"TREE", "SMALL TREE", "BUSH", "BUILDING", "HOUSE", "FOREST BORDER", "FOREST TRIANGLE", "FOREST SQUARE", "CHURCH", "CHAPEL", "CROSS", "BUNKER", "FORTRESS", "FOUNTAIN", "VIEW-TOWER", "LIGHTHOUSE", "QUAY", "FUELSTATION", "HOSPITAL", "FENCE", "WALL", "HIDE", "BUSSTOP", "ROAD", "FOREST", "TRANSMITTER", "STACK", "RUIN", "TOURISM", "WATERTOWER", "TRACK", "MAIN ROAD", "ROCK", "ROCKS", "POWER LINES", "RAILWAY", "POWERSOLAR", "POWERWAVE", "POWERWIND", "SHIPWRECK", "TRAIL"</tt>
<br><br>
<br><br>
Since Arma 3 v1.61.136035 it is possible to switch the sorting algorithm off by providing optional param, which significantly increases the performance of this command, especially if the search is performed with large radius.
Since Arma 3 v1.61.136035 it is possible to switch the sorting algorithm off by providing optional param, which significantly increases the performance of this command, especially if the search is performed with large radius.
<br><br>
<br><br>
Since Arma 3 v1.65.138818 it is possible to switch search and sorting mode between 2D and 3D
Since Arma 3 v1.65.138818 it is possible to switch search and sorting mode between 2D and 3D. |DESCRIPTION=
|DESCRIPTION=
____________________________________________________________________________________________
____________________________________________________________________________________________


|'''nearestTerrainObjects''' [position, types, radius, sort, 2Dmode]
| [[nearestTerrainObjects]] [position, types, radius, sort, 2Dmode] |Syntax=
 
|p1= position:  [[Object]], [[PositionAGL]] or [[Position2D]] - where to find objects, center position |PARAMETER1=
 
|p2= types: [[Array]] - list of types of the objects to search for. <tt>[]</tt> to search without filters |PARAMETER2=
 
|p3= radius: [[Number]] - range from center position to search for objects |PARAMETER3=


|p1 = [position, types, radius, sort, 2Dmode]: [[Array]]|PARAMETER1=
|p4= sort: [[Boolean]] - (Optional, default [[true]]) sort objects by distance to the center or not (''Available since Arma 3 v1.61.136035'') |PARAMETER4=
|p2= position:  [[Object]]  or [[Array]] in format [[PositionAGL]] or [[Position2D]] - where to find objects, center position. |PARAMETER2=
 
|p3= types: [[Array]] - list of types of the objects to search for. |PARAMETER3=
|p5= 2Dmode: [[Boolean]] - (Optional, default [[false]]) the object search and sorting mode: [[true]] - 2D, [[false]] - 3D (''Available since Arma 3 v1.65.138818'') |PARAMETER5=
|p4= radius: [[Number]] - range from center position to search for objects. |PARAMETER4=
|p5= sort (Optional): [[Boolean]] - Sort objects by distance to the center or not. Default: [[true]] - always sort. (''Available since Arma 3 v1.61.136035'') |PARAMETER5=
|p6=2Dmode (Optional): [[Boolean]] - The object search and sorting mode: [[true]] - 2D, [[false]] - 3D. Default: [[false]] - 3D (''Available since Arma 3 v1.65.138818'')|PARAMETER6=


| [[Array]] - array of terrain objects |RETURNVALUE=
| [[Array]] - array of terrain objects |RETURNVALUE=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], ["Tree","Bush"], 200];</code> |EXAMPLE1=
|x1= <code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], ["Tree", "Bush"], 200];</code> |EXAMPLE1=
 
|x2= <code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], ["House"], 200];</code> |EXAMPLE2=
|x2= <code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], ["House"], 200];</code> |EXAMPLE2=
|x3= <code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[2716,2949,0], ["Chapel","Fuelstation"], 100];</code> |EXAMPLE2=
 
|x4= Return every terrain object in 50 metres radius around player sorted, closest first:<code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], [], 50]</code> |EXAMPLE4=
|x3= <code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[2716,2949,0], ["Chapel", "Fuelstation"], 100];</code> |EXAMPLE3=
|x5= Return every terrain object in 50 metres radius around player unsorted:<code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], [], 50, [[false]]]</code> |EXAMPLE5=
 
|x6= Hide all terrain objects command could find:<code>[[if]] ([[isServer]]) [[then]]  
|x4= Return every terrain object in 50 metres radius around player sorted, closest first:<code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], [], 50];</code> |EXAMPLE4=
 
|x5= Return every terrain object in 50 metres radius around player unsorted:<code>[[nearestTerrainObjects]] <nowiki>[</nowiki>[[player]], [], 50, [[false]]];</code> |EXAMPLE5=
 
|x6= Hide all terrain objects [[nearestTerrainObjects]] could find:
<code>[[if]] ([[isServer]]) [[then]]
{
{
{
{
_x [[hideObjectGlobal]] [[true]];
[[_x]] [[hideObjectGlobal]] [[true]];
}  
}
[[forEach]] [[nearestTerrainObjects]]  
[[forEach]] [[nearestTerrainObjects]]
[
[
<nowiki>[</nowiki>[[worldSize]]/2, [[worldSize]]/2],  
<nowiki>[</nowiki>[[worldSize]] / 2, [[worldSize]] / 2],
[],  
[],
[[worldSize]],  
[[worldSize]],
[[false]]
[[false]]
];
];
Line 65: Line 58:


| [[nearestObjects]], [[findNearestEnemy]], [[hideObject]], [[nearestBuilding]], [[nearestObject]], [[nearObjects]], [[nearestLocation]], [[nearEntities]], [[nearTargets]], [[nearSupplies]], [[nearestLocationWithDubbing]], [[nearObjectsReady]], [[nearRoads]] |SEEALSO=
| [[nearestObjects]], [[findNearestEnemy]], [[hideObject]], [[nearestBuilding]], [[nearestObject]], [[nearObjects]], [[nearestLocation]], [[nearEntities]], [[nearTargets]], [[nearSupplies]], [[nearestLocationWithDubbing]], [[nearObjectsReady]], [[nearRoads]] |SEEALSO=
}}
}}


Line 77: Line 69:
<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>


[[Category:Scripting Commands|NEARESTOBJECTS]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Object_Information|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Object_Information|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
Line 88: Line 80:
Since Arma 3 v1.65.138818 the default sorting is done according to 3D distance not [[distance2D]] as before. This is an attempt to correct some very old bug in implementation.  
Since Arma 3 v1.65.138818 the default sorting is done according to 3D distance not [[distance2D]] as before. This is an attempt to correct some very old bug in implementation.  
</dd>
</dd>
</dl>
 
<dl class="command_description">
<dd class="notedate">Posted on December 28, 2016 - 20:21 (UTC)</dd>
<dd class="notedate">Posted on December 28, 2016 - 20:21 (UTC)</dd>
<dt class="note">[[User:Demellion|Demellion]]</dt>
<dt class="note">[[User:Demellion|Demellion]]</dt>
<dd class="note">
<dd class="note">
Be aware that some terrain objects types might be tricky to be found, such as terrain rocks and boulders which are not considered to be "ROCKS" or "ROCK", but "HIDE". Example:
Be aware that some terrain objects types might be tricky to be found, such as terrain rocks and boulders which are not considered to be "ROCKS" or "ROCK", but "HIDE". Example:
<code>nearestTerrainObjects [player, ["HIDE"], 20]; // [939688: bluntstone_01.p3d,939691: garbagebags_f.p3d,939671: wreck_car_f.p3d,939692: junkpile_f.p3d]</code>
<code>nearestTerrainObjects [player, ["HIDE"], 20]; {{cc|[939688: bluntstone_01.p3d,939691: garbagebags_f.p3d,939671: wreck_car_f.p3d,939692: junkpile_f.p3d]}}</code>
</dd>
</dd>
</dl>
 
<dl class="command_description">
<dd class="notedate">Posted on October 31, 2017 - 17:47 (UTC)</dd>
<dd class="notedate">Posted on October 31, 2017 - 17:47 (UTC)</dd>
<dt class="note">[[User:Tajin|Tajin]]</dt>
<dt class="note">[[User:Tajin|Tajin]]</dt>
<dd class="note">
<dd class="note">
Here is a readout for Altis (as of 1.76), showing you the actual usefulness of the different object-types (some of them are apparently not used/defined at all).
Here is a readout for Altis (as of 1.76), showing you the actual usefulness of the different object-types (some of them are apparently not used/defined at all).
Especially the road type names sadly return nothing.
Especially the road type names sadly return nothing.
<spoiler>
*TREE: 263630
*TREE: 263630
*SMALL TREE: 0
*SMALL TREE: 0
Line 145: Line 135:
*SHIPWRECK: 43
*SHIPWRECK: 43
*TRAIL: 0
*TRAIL: 0
</spoiler>
</dd>
</dd>
</dl>
</dl>
<!-- DISCONTINUE Notes -->
<!-- DISCONTINUE Notes -->

Revision as of 23:18, 2 September 2019

Hover & click on the images for description

Description

Description:
Returns a list of nearest terrain objects of the given types to the given position or object, within the specified distance. If more than one object is found they will be ordered according to 3D distance to the object (i.e. the closest one will be first in the array). In contrast to nearestObjects this command returns terrain placed objects like trees, rocks and buildings which don't necessarily need an associated config class.

Possible type names:"TREE", "SMALL TREE", "BUSH", "BUILDING", "HOUSE", "FOREST BORDER", "FOREST TRIANGLE", "FOREST SQUARE", "CHURCH", "CHAPEL", "CROSS", "BUNKER", "FORTRESS", "FOUNTAIN", "VIEW-TOWER", "LIGHTHOUSE", "QUAY", "FUELSTATION", "HOSPITAL", "FENCE", "WALL", "HIDE", "BUSSTOP", "ROAD", "FOREST", "TRANSMITTER", "STACK", "RUIN", "TOURISM", "WATERTOWER", "TRACK", "MAIN ROAD", "ROCK", "ROCKS", "POWER LINES", "RAILWAY", "POWERSOLAR", "POWERWAVE", "POWERWIND", "SHIPWRECK", "TRAIL"

Since Arma 3 v1.61.136035 it is possible to switch the sorting algorithm off by providing optional param, which significantly increases the performance of this command, especially if the search is performed with large radius.

Since Arma 3 v1.65.138818 it is possible to switch search and sorting mode between 2D and 3D.
Groups:
Uncategorised

Syntax

Syntax:
nearestTerrainObjects [position, types, radius, sort, 2Dmode]
Parameters:
position: Object, PositionAGL or Position2D - where to find objects, center position
types: Array - list of types of the objects to search for. [] to search without filters
radius: Number - range from center position to search for objects
sort: Boolean - (Optional, default true) sort objects by distance to the center or not (Available since Arma 3 v1.61.136035)
2Dmode: Boolean - (Optional, default false) the object search and sorting mode: true - 2D, false - 3D (Available since Arma 3 v1.65.138818)
Return Value:
Array - array of terrain objects

Examples

Example 1:
nearestTerrainObjects [player, ["Tree", "Bush"], 200];
Example 2:
nearestTerrainObjects [player, ["House"], 200];
Example 3:
nearestTerrainObjects [[2716,2949,0], ["Chapel", "Fuelstation"], 100];
Example 4:
Return every terrain object in 50 metres radius around player sorted, closest first:nearestTerrainObjects [player, [], 50];
Example 5:
Return every terrain object in 50 metres radius around player unsorted:nearestTerrainObjects [player, [], 50, false];
Example 6:
Hide all terrain objects nearestTerrainObjects could find: if (isServer) then { { _x hideObjectGlobal true; } forEach nearestTerrainObjects [ [worldSize / 2, worldSize / 2], [], worldSize, false ]; };

Additional Information

See also:
nearestObjectsfindNearestEnemyhideObjectnearestBuildingnearestObjectnearObjectsnearestLocationnearEntitiesnearTargetsnearSuppliesnearestLocationWithDubbingnearObjectsReadynearRoads

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

Notes

Bottom Section

Posted on October 31, 2016 - 00:20 (UTC)
Killzone Kid
Since Arma 3 v1.65.138818 the default sorting is done according to 3D distance not distance2D as before. This is an attempt to correct some very old bug in implementation.
Posted on December 28, 2016 - 20:21 (UTC)
Demellion
Be aware that some terrain objects types might be tricky to be found, such as terrain rocks and boulders which are not considered to be "ROCKS" or "ROCK", but "HIDE". Example: nearestTerrainObjects [player, ["HIDE"], 20]; // [939688: bluntstone_01.p3d,939691: garbagebags_f.p3d,939671: wreck_car_f.p3d,939692: junkpile_f.p3d]
Posted on October 31, 2017 - 17:47 (UTC)
Tajin
Here is a readout for Altis (as of 1.76), showing you the actual usefulness of the different object-types (some of them are apparently not used/defined at all). Especially the road type names sadly return nothing.
  • TREE: 263630
  • SMALL TREE: 0
  • BUSH: 747193
  • BUILDING: 0
  • HOUSE: 17472
  • FOREST BORDER: 0
  • FOREST TRIANGLE: 0
  • FOREST SQUARE: 0
  • CHURCH: 54
  • CHAPEL: 165
  • CROSS: 0
  • BUNKER: 0
  • FORTRESS: 0
  • FOUNTAIN: 0
  • VIEW-TOWER: 0
  • LIGHTHOUSE: 7
  • QUAY: 0
  • FUELSTATION: 32
  • HOSPITAL: 1
  • FENCE: 47940
  • WALL: 38943
  • HIDE: 655066
  • BUSSTOP: 0
  • ROAD: 0
  • FOREST: 0
  • TRANSMITTER: 23
  • STACK: 48
  • RUIN: 3
  • TOURISM: 1
  • WATERTOWER: 10
  • TRACK: 0
  • MAIN ROAD: 0
  • ROCK: 5483
  • ROCKS: 0
  • POWER LINES: 2224
  • RAILWAY: 0
  • POWERSOLAR: 10
  • POWERWAVE: 51
  • POWERWIND: 128
  • SHIPWRECK: 43
  • TRAIL: 0
↑ Back to spoiler's top