nearestObject: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "\|x([0-9]) *= * <code>([^<]*)<\/code>" to "|x$1= <sqf>$2</sqf>") |
Lou Montana (talk | contribs) m (Text replacement - "\{\{Note([^<]*)<code>([^<]*)<\/code>" to "{{Note$1<sqf>$2</sqf>") |
||
Line 88: | Line 88: | ||
|timestamp= 20190129153100 | |timestamp= 20190129153100 | ||
|text= The ID for Syntax 4 may be dynamically obtained via the following (as of {{arma3}} v1.88): | |text= The ID for Syntax 4 may be dynamically obtained via the following (as of {{arma3}} v1.88): | ||
< | <sqf>// returns Object Terrain/Visitor ID, or -1 if no ID found (invalid/null object) | ||
cursorObject call { | cursorObject call { | ||
private _obj = str (param [0, objNull]); | private _obj = str (param [0, objNull]); | ||
Line 101: | Line 101: | ||
}; | }; | ||
_id | _id | ||
};</ | };</sqf> | ||
}} | }} | ||
Line 109: | Line 109: | ||
|text= Note, that if you want to check for the nearest Unit you have to check for {{ic|CAManBase}} instead of {{ic|Man}}, since {{ic|Man}} will also return any wildlife population in that area: | |text= Note, that if you want to check for the nearest Unit you have to check for {{ic|CAManBase}} instead of {{ic|Man}}, since {{ic|Man}} will also return any wildlife population in that area: | ||
< | <sqf>nearestObject [player, "Man"]; // could possibly return rabbits or other wildlife | ||
nearestObject [player, "CAManBase"]; // only returns units | nearestObject [player, "CAManBase"]; // only returns units | ||
</ | </sqf> | ||
}} | }} |
Revision as of 10:41, 13 May 2022
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 Visitor id (see getObjectID) in string format (since Arma 3 v2.10)
- 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:
_nObject = [0,0,0] nearestObject 123456;
- Example 3:
- 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: - 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:
- 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):
// 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 ofMan
, sinceMan
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