nearestObject: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " +" to " ") |
No edit summary |
||
(64 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{RV|type=command | {{RV|type=command | ||
| ofp | |game1= ofp | ||
|version1= 1.00 | |||
|1.00 | |game2= ofpe | ||
|version2= 1.00 | |||
|game3= arma1 | |||
|version3= 1.00 | |||
|game4= arma2 | |||
|version4= 1.00 | |||
|game5= arma2oa | |||
|version5= 1.50 | |||
|game6= tkoh | |||
|version6= 1.00 | |||
|game7= arma3 | |||
|version7= 0.50 | |||
|gr1= Object Detection | |gr1= Object Detection | ||
| 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. | |descr= 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. | |||
{{Feature | | {{Feature|informative| | ||
* in | * in {{ofp}}, only objects of the exact provided class are found. | ||
* if an object ID is used ( | * if an object ID is used ({{Link|#Syntax 4}}, see {{Link|#Example 2}}) the search range is unlimited | ||
}} | |||
| [[nearestObject]] [position, type] | |s1= [[nearestObject]] [position, type] | ||
|p1= | |p1= position: [[Object]] or [[Array]] format [[Position#Introduction|Position2D]] or [[Position#Introduction|Position3D]] - position to start search at | ||
| | |p2= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]]) | ||
| [[Object]] - | |r1= [[Object]] - nearest object, [[objNull]] otherwise | ||
|s2= [[nearestObject]] position | |s2= [[nearestObject]] position | ||
|p21= position: [[ | |p21= position: [[Array]] format [[Position#Introduction|Position2D]] or [[Position#Introduction|Position3D]] - position to start search at | ||
|r2= [[Object]] - | |r2= [[Object]] - nearest object, [[objNull]] otherwise | ||
|s3= position [[nearestObject]] | |s3= position [[nearestObject]] typeOrId | ||
|p41= position: [[Position3D]] or [[Position2D]] - position to start search at | |p41= position: [[Position#Introduction|Position3D]] or [[Position#Introduction|Position2D]] - position to start search at | ||
|p42= | |p42= typeOrId: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]]) or {{GVI|arma3|2.10|size= 0.75}} Visitor id (see [[getObjectID]]) | ||
|r3= [[Object]] - nearest object, [[objNull]] otherwise | |r3= [[Object]] - nearest object, [[objNull]] otherwise | ||
Line 38: | Line 56: | ||
|s4= position [[nearestObject]] id | |s4= position [[nearestObject]] id | ||
|p61= position: [[ | |p61= position: [[Array]] format [[Position#Introduction|Position2D]] or [[Position#Introduction|Position3D]] - position to start search at | ||
|p62= id: [[Number]] - object Visitor id | |p62= id: [[Number]] - object Visitor id | ||
Line 44: | Line 62: | ||
|r4= [[Object]] - nearest object, [[objNull]] otherwise | |r4= [[Object]] - nearest object, [[objNull]] otherwise | ||
|x1= < | |x1= <sqf> | ||
_nObject = | _nObject = nearestObject [2345, 6789]; | ||
_nObject = nearestObject [player, "StreetLamp"]; | |||
</sqf> | |||
|x2= Return the object with ID 123456: | |x2= Return the object with ID 123456: | ||
< | <sqf>_nObject = [0,0,0] nearestObject 123456;</sqf> | ||
|x3= < | |x3= <sqf>_nObject = getPos player nearestObject "StreetLamp";</sqf> | ||
|x4= Return the nearest object with ([[typeOf]] _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range: | |x4= Return the nearest object with ([[typeOf]] _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range: | ||
< | <sqf>_nObject = _position nearestObject -1;</sqf> | ||
Return the nearest object with ([[typeOf]] _nObject != ""). Search range is 50m: | Return the nearest object with ([[typeOf]] _nObject != ""). Search range is 50m: | ||
< | <sqf>_nObject = nearestObject _position;</sqf> | ||
|x5= (See also [[allMissionObjects]]): | |x5= (See also [[allMissionObjects]]): | ||
< | <sqf> | ||
_step | _blood = nearestObject [player, "#slop"]; | ||
_track | _step = nearestObject [player, "#mark"]; | ||
_crater = | _track = nearestObject [player, "#track"]; | ||
_crater = nearestObject [player, "#crater"]; | |||
</sqf> | |||
|seealso= [[nearestObjects]] | |seealso= [[nearestObjects]] [[nearObjectsReady]] [[nearObjects]] [[objectFromNetId]] [[nearEntities]] [[entities]] [[object]] [[nearestBuilding]] [[nearestTerrainObjects]] [[nearestMines]] | ||
}} | }} | ||
{{Note | |||
|user= Gnashes | |||
|timestamp= 20190129153100 | |||
|text= The ID for Syntax 4 may be dynamically obtained via the following (as of {{arma3}} v1.88): | |||
(for {{arma3}} v2.10 or newer, use [[getObjectID]] instead) | |||
<sqf> | |||
// 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 | |||
}; | }; | ||
_id | _id | ||
}; | }; | ||
</sqf> | |||
}} | |||
{{Note | |||
|user= blackfisch | |||
|timestamp= 20200212085500 | |||
|text= Note, that if you want to check for the nearest Unit you have to check for {{hl|CAManBase}} instead of {{hl|Man}}, since {{hl|Man}} will also return any wildlife population in that area: | |||
nearestObject [player, "CAManBase"]; | <sqf> | ||
</ | nearestObject [player, "Man"]; // could possibly return rabbits or other wildlife | ||
nearestObject [player, "CAManBase"]; // only returns units | |||
</sqf> | |||
}} |
Latest revision as of 19:21, 19 July 2024
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:
- Object Detection
Syntax 1
- Syntax:
- nearestObject [position, type]
- Parameters:
- position: Object or Array format Position2D or Position3D - 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: Array format Position2D or Position3D - position to start search at
- Return Value:
- Object - nearest object, objNull otherwise
Syntax 3
- Syntax:
- position nearestObject typeOrId
- Parameters:
- position: Position3D or Position2D - position to start search at
- typeOrId: String - type of object (see typeOf, class type) or 2.10 Visitor id (see getObjectID)
- Return Value:
- Object - nearest object, objNull otherwise
Syntax 4
- Syntax:
- position nearestObject id
- Parameters:
- position: Array format Position2D or Position3D - position to start search at
- id: Number - object Visitor id
- Return Value:
- Object - nearest object, objNull otherwise
Examples
- Example 1:
- Example 2:
- Return the object with ID 123456:
- Example 3:
- Example 4:
- Return the nearest object with (typeOf _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range:
Return the nearest object with (typeOf _nObject != ""). Search range is 50m:
- Example 5:
- (See also allMissionObjects):
Additional Information
- See also:
- nearestObjects nearObjectsReady nearObjects objectFromNetId nearEntities entities object nearestBuilding nearestTerrainObjects nearestMines
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
- Posted on Jan 29, 2019 - 15:31 (UTC)
-
The ID for Syntax 4 may be dynamically obtained via the following (as of Arma 3 v1.88):
(for Arma 3 v2.10 or newer, use getObjectID instead)
// 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 };
- Posted on Feb 12, 2020 - 08:55 (UTC)
- Note, that if you want to check for the nearest Unit you have to check for CAManBase instead of Man, since Man will also return any wildlife population in that area:
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.00
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Operation Flashpoint: Elite: Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Object Detection