nearestObject: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(see also)
(46 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[[Category:Scripting Commands]]
{{Command|= Comments
[[Category:Scripting Commands OFP 1.97]]
____________________________________________________________________________________________
[[Category:Scripting Commands OFP 1.46]]
[[Category:Scripting Commands ArmA]]


back to [[Scripting_Reference#A|COMREF]]
| ofp |= Game name


<h2 style="color:#000066">'''nearestObject ''pos'''''</h2>
|1.00|= Game version
<h2 style="color:#000066">'''''type'' nearestObject ''pos'''''</h2>
____________________________________________________________________________________________
<h2 style="color:#000066">'''''id'' nearestObject ''pos'''''</h2>


| 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
____________________________________________________________________________________________


'''Operand types:'''
| '''nearestObject''' [position, type] |= Syntax


'''pos:''' [[Array]]
|p1= [position, type]: [[Array]] |=
|p2= position:  [[Position3D]] or [[Position2D]] or [[Object]] - position to start search at|=
|p3= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]])|=


'''type:''' [[String]]
| [[Object]] - Nearest object, [[objNull]] otherwise |= Return value


'''id:''' [[Number]]
____________________________________________________________________________________________


'''Type of returned value:'''
|s2= '''nearestObject''' position |= Syntax


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


'''Compatibility:'''
|r2= [[Object]] - Nearest object, [[objNull]] otherwise |= Return value
____________________________________________________________________________________________


Binary variants added in '''ArmA'''
|s3= position '''nearestObject''' type |=


'''Description:'''
|p41= position: [[Position3D]] or [[Position2D]] - position to start search at|=
|p42= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]])|=


Nearest building of given type to given '''position''' or '''object'''.
|r3= [[Object]] - Nearest object, [[objNull]] otherwise |=


For ''nearestObject pos'', pos may be '''''[x, y ,z, "type"]''''' or '''''[object, "type"]''''' or even '''''[x, y, z]'''''.
____________________________________________________________________________________________


For ''id nearestObject pos'' or ''id nearestObject pos'', pos may be '''''[x, y ,z]'''''.
|s4= position '''nearestObject''' id |=


|p61= position: [[Position3D]] or [[Position2D]] - position to start search at|=
|p62= id: [[Number]] - object Visitor id|=


'''Example:'''
|r4= [[Object]] - Nearest object, [[objNull]] otherwise |=
____________________________________________________________________________________________


_nObject = '''nearestObject''' [ [[player]], "StreetLamp"]
 
|x1= <code>_nObject = [[nearestObject]] [2345,6789];
_nObject = [[nearestObject]] <nowiki>[</nowiki>[[player]], "StreetLamp"];
</code>  |= Example 1
|x2= Return the object with ID 123456:<code>_nObject = [0,0,0] [[nearestObject]] 123456; </code> |= Example 2
|x3= <code>_nObject = [[getPos]] [[player]] [[nearestObject]] "StreetLamp"; </code> |= Example 3
|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:
<code>_nObject = [[nearestObject]] _position; </code>
|= Example 4
|x5= (See also [[allMissionObjects]]): <code>_blood = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#slop"];
_step = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#mark"];
_track = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#track"];
_crater = [[nearestObject]] <nowiki>[</nowiki>[[player]], "#crater"];</code> |= Example 5
____________________________________________________________________________________________


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


'''Comments'''
}}


This command can only find objects up to 50 meters away.
<h3 style="display:none">Notes</h3>
 
<dl class="command_description">
<!-- Note Section BEGIN -->
 
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
 
[[Category:Scripting Commands|NEARESTOBJECT]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|NEARESTOBJECT]]
[[Category:Scripting Commands OFP 1.46|NEARESTOBJECT]]
[[Category:Scripting Commands ArmA|NEARESTOBJECT]]
[[Category:Command_Group:_Object_Information|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Revision as of 20:32, 11 March 2017

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 or Object - 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