nearestObject: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "|= |p3=" to "|Parameter2= |p3=") |
Lou Montana (talk | contribs) |
||
Line 7: | Line 7: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| 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. | | Returns the nearest object of given type (or inherited classes) 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. | ||
{{Informative | | |||
* in OFP, only objects of the exact provided class are found. | |||
* if an object ID is used (Alternative Syntax 3, see '''Example 2''') the search range is unlimited}} |DESCRIPTION= | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| | | [[nearestObject]] [position, type] |SYNTAX= | ||
|p1= [position, type]: [[Array]] |Parameter1= | |p1= [position, type]: [[Array]] |Parameter1= | ||
|p2= position: [[Position3D]] or [[Position2D]] or [[Object]] - position to start search at|Parameter2= | |p2= position: [[Position3D]] or [[Position2D]] or [[Object]] - position to start search at |Parameter2= | ||
|p3= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]])|= | |p3= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]]) |Parameter3= | ||
| [[Object]] - Nearest object, [[objNull]] otherwise |RETURNVALUE= | | [[Object]] - Nearest object, [[objNull]] otherwise |RETURNVALUE= | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|s2= | |s2= [[nearestObject]] position |SYNTAX2= | ||
|p21= position: | |p21= position: [[Position3D]] or [[Position2D]] - position to start search at |PARAMETER21= | ||
|r2= [[Object]] - Nearest object, [[objNull]] otherwise | | |r2= [[Object]] - Nearest object, [[objNull]] otherwise |RETURNVALUE2= | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|s3= position | |s3= position [[nearestObject]] type |SYNTAX3= | ||
|p41= position: [[Position3D]] or [[Position2D]] - position to start search at| | |p41= position: [[Position3D]] or [[Position2D]] - position to start search at |PARAMETER41= | ||
| | |p42= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]]) |PARAMETER42= | ||
|r3= [[Object]] - nearest object, [[objNull]] otherwise |RETURNVALUE3= | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|s4= position | |s4= position [[nearestObject]] id |SYNTAX4= | ||
|p61= position: [[Position3D]] or [[Position2D]] - position to start search at |PARAMETER61= | |||
|p62= id: [[Number]] - object Visitor id |PARAMETER62= | |||
|p62= id: [[Number]] - object Visitor id|= | |||
|r4= [[Object]] - | |r4= [[Object]] - nearest object, [[objNull]] otherwise |RETURNVALUE4= | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|x1= <code>_nObject = [[nearestObject]] [2345,6789]; | |x1= <code>_nObject = [[nearestObject]] [2345, 6789]; | ||
_nObject = [[nearestObject]] <nowiki | _nObject = [[nearestObject]] [<nowiki/>[[player]], "StreetLamp"];</code> |EXAMPLE1= | ||
</code> | |||
|x2= Return the object with ID 123456:<code>_nObject = [0,0,0] [[nearestObject]] 123456; </code> |EXAMPLE2= | |x2= Return the object with ID 123456: | ||
<code>_nObject = [0,0,0] [[nearestObject]] 123456;</code> |EXAMPLE2= | |||
|x3= <code>_nObject = [[getPos]] [[player]] [[nearestObject]] "StreetLamp"; </code> |EXAMPLE3= | |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> |EXAMPLE4= | ||
|x5= (See also [[allMissionObjects]]): <code>_blood = [[nearestObject]] <nowiki | |x5= (See also [[allMissionObjects]]): | ||
_step = [[nearestObject]] <nowiki | <code>_blood = [[nearestObject]] [<nowiki/>[[player]], "#slop"]; | ||
_track = [[nearestObject]] <nowiki | _step = [[nearestObject]] [<nowiki/>[[player]], "#mark"]; | ||
_crater = [[nearestObject]] <nowiki | _track = [[nearestObject]] [<nowiki/>[[player]], "#track"]; | ||
_crater = [[nearestObject]] [<nowiki/>[[player]], "#crater"];</code> |EXAMPLE5= | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| | | [[nearestObjects]], [[nearObjectsReady]], [[nearObjects]], [[objectFromNetId]], [[nearEntities]], [[entities]], [[object]], [[nearestBuilding]], [[nearestTerrainObjects]] |SEEALSO= | ||
}} | }} | ||
Line 76: | Line 84: | ||
<h3 style="display:none">Bottom Section</h3> | <h3 style="display:none">Bottom Section</h3> | ||
[[Category:Scripting Commands| | [[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Scripting Commands OFP 1.46|{{uc:{{PAGENAME}}}}]] | |||
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]] | |||
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]] | [[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]] | |||
[[Category:Scripting Commands ArmA | |||
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]] | [[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]] | [[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]] | [[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Command_Group:_Object_Information|{{uc:{{PAGENAME}}}}]] | |||
<!-- CONTINUE Notes --> | <!-- CONTINUE Notes --> | ||
Line 92: | Line 100: | ||
<dd class="note"> | <dd class="note"> | ||
The ID for Alternative Syntax 3 may be dynamically obtained via the following (as of Arma 3 v1.88): | The ID for Alternative Syntax 3 may be dynamically obtained via the following (as of Arma 3 v1.88): | ||
<code>{{cc|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); | [[private]] _find [[=]] ((_obj [[find]] "#") + 2); | ||
[[if]] (_find > 1) [[then]] { | [[if]] (_find > 1) [[then]] { | ||
[[private]] _len [[=]] ((_obj [[find]] ":") - _find); | [[private]] _len [[=]] ((_obj [[find]] ":") - _find); | ||
_id [[=]] _obj [[select]] [_find,_len]; | _id [[=]] _obj [[select]] [_find, _len]; | ||
[[parseNumber]] _id; | [[parseNumber]] _id; | ||
}; | }; |
Revision as of 23:18, 30 September 2019
Description
- Description:
- Returns the nearest object of given type (or inherited classes) 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.
- 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 };
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.00
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands OFP 1.46
- Scripting Commands OFP 1.96
- Scripting Commands OFP 1.99
- Scripting Commands ArmA
- Scripting Commands ArmA2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters
- Command Group: Object Information