nearestObject: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Command " to "{{RV|type=command ")
m (Text replacement - " *\| *PARAMETER[0-9]{1,3} *= * " to " ")
Line 24: Line 24:
|s2= [[nearestObject]] position
|s2= [[nearestObject]] position


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


|r2= [[Object]] - Nearest object, [[objNull]] otherwise
|r2= [[Object]] - Nearest object, [[objNull]] otherwise
Line 30: Line 30:
|s3= position [[nearestObject]] type
|s3= position [[nearestObject]] type


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


|p42= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]]) |PARAMETER42=
|p42= type: [[String]] - type of object (see [[typeOf]], [[CfgVehicles|class type]])


|r3= [[Object]] - nearest object, [[objNull]] otherwise
|r3= [[Object]] - nearest object, [[objNull]] otherwise
Line 38: Line 38:
|s4= position [[nearestObject]] id
|s4= position [[nearestObject]] id


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


|p62= id: [[Number]] - object Visitor id |PARAMETER62=
|p62= id: [[Number]] - object Visitor id


|r4= [[Object]] - nearest object, [[objNull]] otherwise
|r4= [[Object]] - nearest object, [[objNull]] otherwise

Revision as of 19:13, 29 January 2021

Hover & click on the images for description

Description

Description:
Description needed
Groups:
Object Detection

Syntax 1

Syntax:
Syntax needed
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:
Return value needed

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:
See also needed

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 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 };
Posted on February 12, 2020 - 08:55 (UTC)
blackfisch
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: nearestObject [player, "Man"]; // could possibly return rabbits or other wildlife nearestObject [player, "CAManBase"]; // only returns units