nearestObject: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Alternative Syntax 2 doesn't accept objects, only position format.)
m (template:command argument fix)
Line 8: Line 8:


| Returns the nearest object of given type to given position within a sphere. Hardcoded radius is 50 meters. Unlike with [[nearestObjects]], where distance is measured in 2D space, [[nearestObject]] will be closest object in 3D space.<br><br>
| Returns the nearest object of given type to given position within a sphere. Hardcoded radius is 50 meters. Unlike with [[nearestObjects]], where distance is measured in 2D space, [[nearestObject]] will be closest object in 3D space.<br><br>
If object class type is used, any object derived from the type is found as well (In OFP however, only objects with exactly the type given are found). If object ID passed as an argument (as in example 2) the search range is unlimited.|= Description
If object class type is used, any object derived from the type is found as well (In OFP however, only objects with exactly the type given are found). If object ID passed as an argument (as in example 2) the search range is unlimited.|DESCRIPTION=
____________________________________________________________________________________________
____________________________________________________________________________________________


| '''nearestObject''' [position, type] |= Syntax
| '''nearestObject''' [position, type] |SYNTAX=


|p1= [position, type]: [[Array]] |=
|p1= [position, type]: [[Array]] |=
Line 17: Line 17:
|p3= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]])|=
|p3= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]])|=


| [[Object]] - Nearest object, [[objNull]] otherwise |= Return value
| [[Object]] - Nearest object, [[objNull]] otherwise |RETURNVALUE=


____________________________________________________________________________________________
____________________________________________________________________________________________


|s2= '''nearestObject''' position |= Syntax
|s2= '''nearestObject''' position |SYNTAX=


|p21= position:  [[Position3D]] or [[Position2D]] - position to start search at|=
|p21= position:  [[Position3D]] or [[Position2D]] - position to start search at|=


|r2= [[Object]] - Nearest object, [[objNull]] otherwise |= Return value
|r2= [[Object]] - Nearest object, [[objNull]] otherwise |RETURNVALUE=
____________________________________________________________________________________________
____________________________________________________________________________________________


Line 48: Line 48:
|x1= <code>_nObject = [[nearestObject]] [2345,6789];
|x1= <code>_nObject = [[nearestObject]] [2345,6789];
_nObject = [[nearestObject]] <nowiki>[</nowiki>[[player]], "StreetLamp"];
_nObject = [[nearestObject]] <nowiki>[</nowiki>[[player]], "StreetLamp"];
</code>  |= Example 1
</code>  |EXAMPLE1=
|x2= Return the object with ID 123456:<code>_nObject = [0,0,0] [[nearestObject]] 123456; </code> |= Example 2
|x2= Return the object with ID 123456:<code>_nObject = [0,0,0] [[nearestObject]] 123456; </code> |EXAMPLE2=
|x3= <code>_nObject = [[getPos]] [[player]] [[nearestObject]] "StreetLamp"; </code> |= Example 3
|x3= <code>_nObject = [[getPos]] [[player]] [[nearestObject]] "StreetLamp"; </code> |EXAMPLE3=
|x4= Return the nearest object with ([[typeOf]] _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range:<code>_nObject = _position [[nearestObject]] -1; </code>
|x4= Return the nearest object with ([[typeOf]] _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range:<code>_nObject = _position [[nearestObject]] -1; </code>
Return the nearest object with ([[typeOf]] _nObject != ""). Search range is 50m:
Return the nearest object with ([[typeOf]] _nObject != ""). Search range is 50m:
<code>_nObject = [[nearestObject]] _position; </code>
<code>_nObject = [[nearestObject]] _position; </code>
  |= Example 4
  |EXAMPLE4=
|x5= (See also [[allMissionObjects]]): <code>_blood = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#slop"];
|x5= (See also [[allMissionObjects]]): <code>_blood = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#slop"];
_step = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#mark"];
_step = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#mark"];
_track = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#track"];
_track = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#track"];
_crater = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#crater"];</code> |= Example 5
_crater = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#crater"];</code> |EXAMPLE5=
____________________________________________________________________________________________
____________________________________________________________________________________________


|  [[nearestObjects]], [[nearObjectsReady]], [[nearObjects]], [[objectFromNetId]], [[nearEntities]], [[entities]], [[object]], [[nearestBuilding]], [[nearestTerrainObjects]] |= See also
|  [[nearestObjects]], [[nearObjectsReady]], [[nearObjects]], [[objectFromNetId]], [[nearEntities]], [[entities]], [[object]], [[nearestBuilding]], [[nearestTerrainObjects]] |SEEALSO=


}}
}}

Revision as of 14:44, 7 April 2019

Hover & click on the images for description

Description

Description:
Returns the nearest object of given type to given position within a sphere. Hardcoded radius is 50 meters. Unlike with nearestObjects, where distance is measured in 2D space, nearestObject will be closest object in 3D space.

If object class type is used, any object derived from the type is found as well (In OFP however, only objects with exactly the type given are found). If object ID passed as an argument (as in example 2) the search range is unlimited.
Groups:
Uncategorised

Syntax 1

Syntax:
nearestObject [position, type]
Parameters:
[position, type]: Array
position: Position3D or Position2D or Object - position to start search at
type: String - type of object (see typeOf, class type)
Return Value:
Object - Nearest object, objNull otherwise

Syntax 2

Syntax:
nearestObject position
Parameters:
position: Position3D or Position2D - position to start search at
Return Value:
Object - Nearest object, objNull otherwise

Syntax 3

Syntax:
position nearestObject type
Parameters:
position: Position3D or Position2D - position to start search at
type: String - type of object (see typeOf, class type)
Return Value:
Object - Nearest object, objNull otherwise

Syntax 4

Syntax:
position nearestObject id
Parameters:
position: Position3D or Position2D - position to start search at
id: Number - object Visitor id
Return Value:
Object - Nearest object, objNull otherwise

Examples

Example 1:
_nObject = nearestObject [2345,6789]; _nObject = nearestObject [player, "StreetLamp"];
Example 2:
Return the object with ID 123456:_nObject = [0,0,0] nearestObject 123456;
Example 3:
_nObject = getPos player nearestObject "StreetLamp";
Example 4:
Return the nearest object with (typeOf _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range:_nObject = _position nearestObject -1; Return the nearest object with (typeOf _nObject != ""). Search range is 50m: _nObject = nearestObject _position;
Example 5:
(See also allMissionObjects): _blood = nearestObject [player, "#slop"]; _step = nearestObject [player, "#mark"]; _track = nearestObject [player, "#track"]; _crater = nearestObject [player, "#crater"];

Additional Information

See also:
nearestObjectsnearObjectsReadynearObjectsobjectFromNetIdnearEntitiesentitiesobjectnearestBuildingnearestTerrainObjects

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 January 29, 2019 - 15:31 (UTC)
Gnashes
The ID for Alternative Syntax 3 may be dynamically obtained via the following (as of Arma 3 v1.88): //Returns Object Terrain/Visitor ID, or -1 if no ID found (invalid/null object) cursorObject call { private _obj = str(param[0,objNull]); private _id = -1; private _find = ((_obj find "#") + 2); if (_find > 1) then { private _len = ((_obj find ":") - _find); _id = _obj select [_find,_len]; parseNumber _id; }; _id };