BIS fnc findSafePos: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\| *(arg|eff|mp|serverExec|gr[0-9]) *= *(.*) * *\|([^=]{12})" to "|$1=$2 |descr=$3")
m (Text replacement - "[[Image:" to "[[File:")
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{RV|type=function
{{RV|type=function


| arma2
|game1= arma2
|1.00
|version1= 1.00


|game2= arma2oa
|game2= arma2oa
Line 15: Line 15:
|gr1= Positions
|gr1= Positions


|descr= This function generates position on a map according to several given parameters (see diagram):<br><br>
|descr= This function generates position on a map according to several given parameters (see diagram).
[[Image:bis_fnc_findsafepos.jpg|800px]]
[[File:bis_fnc_findsafepos.jpg|600px|thumb|Diagram]]
<br>
The position '''pos''' will be generated inside an area which resides between '''minDist''' and '''maxDist''' from the given '''center'''. If '''objDist''' is also specified, the position will be selected '''objDist''' away from nearest terrain object. If '''maxGrad''' > 0 then the position will be also checked for how flat the area around is within '''objDist''' radius. The function can additionally be instructed to generate position specifically on water or land ('''waterMode''') or on a shoreline ('''shoreMode'''). The '''shoreLine''' param will be ignored if position is not requested specifically on land.<br><br>
The position '''pos''' will be generated inside an area which resides between '''minDist''' and '''maxDist''' from the given '''center'''. If '''objDist''' is also specified, the position will be selected '''objDist''' away from nearest terrain object. If '''maxGrad''' > 0 then the position will be also checked for how flat the area around is within '''objDist''' radius. The function can additionally be instructed to generate position specifically on water or land ('''waterMode''') or on a shoreline ('''shoreMode'''). The '''shoreLine''' param will be ignored if position is not requested specifically on land.<br><br>
Additionally, generated position could be checked against the list of blacklisted positions '''blacklistPos'''. If search for suitable position failed, '''defaultPos''' position will be used. The format for '''defaultPos''' is array with 2 positions: [posOnLand, posOnWater].
Additionally, generated position could be checked against the list of blacklisted positions '''blacklistPos'''. If search for suitable position failed, '''defaultPos''' position will be used. The format for '''defaultPos''' is array with 2 positions: [posOnLand, posOnWater].


|s1=[center, minDist, maxDist, objDist, waterMode, maxGrad, shoreMode, blacklistPos, defaultPos] call [[BIS_fnc_findSafePos]]
|s1= [center, minDist, maxDist, objDist, waterMode, maxGrad, shoreMode, blacklistPos, defaultPos] call [[BIS_fnc_findSafePos]]


|p1= center (Optional): center position. Could be one of:  
|p1= center: (Optional, default <sqf inline>[]</sqf>) center position. Can be one of:  
* [[Array]] - [[Position2D]] or [[Position3D]] - position
* [[Array]] - position in format [[Position#Introduction|Position2D]] or [[Position#Introduction|Position3D]]
* [[Object]] - object which position will be used
* [[Object]] - object which position will be used
* [[Nothing]] - when passing empty array [] or nothing, the world's "safePositionAnchor" entry will be used. (Default: []).
* [[Nothing]] - when passing empty array [] or nothing, the world's "safePositionAnchor" entry will be used


|p2= minDist (Optional): [[Number]] - minimum distance from the center position. (Default: 0).
|p2= minDist: [[Number]] - (Optional, default 0) minimum distance from the center position


|p3= maxDist (Optional): [[Number]] - maximum distance from the center position. If -1, the world's "safePositionRadius" entry will be used. (Default: -1).
|p3= maxDist: [[Number]] - (Optional, default -1) maximum distance from the center position. If -1, the world's "safePositionRadius" entry will be used


|p4= objDist (Optional): [[Number]] - minimum distance from the resulting position to the center of nearest object. Specifying quite large distance here will slow the function and might often fail to find suitable position. Recommended value: 0 - 10. (Default: 0).
|p4= objDist: [[Number]] - (Optional, default 0) minimum distance from the resulting position to the center of nearest object. Specifying quite large distance here will slow the function and might often fail to find suitable position. Recommended value: 0..10


|p5= waterMode (Optional): [[Number]] - water mode (Default: 0). Could be one of:
|p5= waterMode: [[Number]] - (Optional, default 0) water mode. Can be one of:
* 0 - cannot be in water
* 0 - cannot be in water
* 1 - can either be in water or not
* 1 - can either be in water or not
* 2 - must be in water
* 2 - must be in water


|p6= maxGrad (Optional): [[Number]] - maximum terrain gradient (hill steepness). A quite small non-zero value could result in failure to find suitable position. Recommended: 0.1+ (Default: 0).
|p6= maxGrad: [[Number]] - (Optional, default 0) maximum terrain gradient (hill steepness). A quite small non-zero value could result in failure to find suitable position. Recommended: 0.1+


|p7= shoreMode (Optional): [[Number]] - shore mode (Default: 0). Could be one of:
|p7= shoreMode: [[Number]] - (Optional, default 0) shore mode. Can be one of:
* 0 - does not have to be at a shore
* 0 - does not have to be at a shore
* 1 - must be at a shore
* 1 - must be at a shore


|p8= blacklistPos (Optional): [[Array]] - List of blacklisted areas in format [area1, area2, area3... areaN] (Default: []). Area could be one of:
|p8= blacklistPos: [[Array]] - (Optional, default <sqf inline>[]</sqf>) list of blacklisted areas in format [area1, area2, area3... areaN]. Can be one of:
* [[Array]] - in format [topLeftCorner, bottomRightCorner] - top and bottom coordinates of blacklisted area
* [[Array]] - in format [topLeftCorner, bottomRightCorner] - top and bottom coordinates of blacklisted area
* [[Object]] - trigger area
* [[Object]] - trigger area
Line 52: Line 51:
* [[Array]] - array in format [center, distance] or [center, a, b, angle, rect] or [center, a, b, angle, rect, height]
* [[Array]] - array in format [center, distance] or [center, a, b, angle, rect] or [center, a, b, angle, rect, height]


|p9= defaultPos (Optional): [[Array]] - default position when no position is found (Default: []). Array format is [landPosition, seaPosition], where:  
|p9= defaultPos: [[Array]] - (Optional, default <sqf inline>[]</sqf>) default position when no position is found. Array format is [landPosition, seaPosition], where:  
* landPosition: [[Array]] - in format [x,y] or [x,y,z] - default position on land
* landPosition: [[Array]] - in format [x,y] or [x,y,z] - default position on land
* seaPosition: [[Array]] - in format [x,y] or [x,y,z] - default position on water
* seaPosition: [[Array]] - in format [x,y] or [x,y,z] - default position on water


|r1=[[Array]] - in format [x,y] on success. When position cannot be found at all, default map center position is returned, which will be in format [x,y,0]
|r1= [[Array]] - in format [x,y] on success. When position cannot be found at all, default map center position is returned, which will be in format [x,y,0]


|x1= Find position minimum 1m from from player but not further than 150m, not closer than 3m to any other object, not in the water, maximum gradient of 20, not on the shoreline: <code>_pos = [<nowiki/>[[player]], 1, 150, 3, 0, 20, 0] [[call]] [[BIS_fnc_findSafePos]];</code>
|x1= Find position minimum 1m from from player but not further than 150m, not closer than 3m to any other object, not in the water, maximum gradient of 20, not on the shoreline:
<sqf>private _pos = [player, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;</sqf>


|x2= <code>_pos = [<nowiki/>[[getPos]] [[player]], 2000, 5000, 1, 0, 0.7, 0, [], [<nowiki/>[[getPos]] [[player]], [[getPos]] [[player]]<nowiki>]</nowiki>] [[call]] [[BIS_fnc_findSafePos]];</code>
|x2= <sqf>private _pos = [getPos player, 2000, 5000, 1, 0, 0.7, 0, [], [getPos player, getPos player]] call BIS_fnc_findSafePos;</sqf>


|x3= <code>_pos = [<nowiki/>[], 0, 1000] [[call]] [[BIS_fnc_findSafePos]];</code>
|x3= <sqf>private _pos = [[], 0, 1000] call BIS_fnc_findSafePos;</sqf>


|seealso= [[BIS_fnc_randomPosTrigger]], [[BIS_fnc_randomPos]]
|seealso= [[BIS_fnc_randomPosTrigger]] [[BIS_fnc_randomPos]]
}}
}}


[[Category:{{Name|arma2oa}}: Functions|{{uc:findSafePos}}]]
{{Note
[[Category:{{Name|tkoh}}: Functions|{{uc:findSafePos}}]]
|user= Killzone_Kid
[[Category:{{Name|arma3}}: Functions|{{uc:findSafePos}}]]
|timestamp= 20170315193000
|text= To make sure position is not inside a building, increase distance to nearest object param.
}}


<dl class="command_description">
{{Note
 
|user= AgentRev
<dt></dt>
|timestamp= 20210924222305
<dd class="notedate">Posted on March 15, 2017 - 19:30 (UTC)</dd>
|text= If ''objDist'' &gt; 0, this function will unfortunately treat all roads and trails seen on the map as obstacles to avoid, due to its unfiltered usage of [[nearestTerrainObjects]].
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
}}
<dd class="note">
To make sure position is not inside a building, increase distance to nearest object param.
</dd>
 
</dl>

Latest revision as of 23:11, 20 November 2023

Hover & click on the images for description

Description

Description:
This function generates position on a map according to several given parameters (see diagram).
Diagram

The position pos will be generated inside an area which resides between minDist and maxDist from the given center. If objDist is also specified, the position will be selected objDist away from nearest terrain object. If maxGrad > 0 then the position will be also checked for how flat the area around is within objDist radius. The function can additionally be instructed to generate position specifically on water or land (waterMode) or on a shoreline (shoreMode). The shoreLine param will be ignored if position is not requested specifically on land.

Additionally, generated position could be checked against the list of blacklisted positions blacklistPos. If search for suitable position failed, defaultPos position will be used. The format for defaultPos is array with 2 positions: [posOnLand, posOnWater].
Execution:
call
Groups:
Positions

Syntax

Syntax:
[center, minDist, maxDist, objDist, waterMode, maxGrad, shoreMode, blacklistPos, defaultPos] call BIS_fnc_findSafePos
Parameters:
center: (Optional, default []) center position. Can be one of:
  • Array - position in format Position2D or Position3D
  • Object - object which position will be used
  • Nothing - when passing empty array [] or nothing, the world's "safePositionAnchor" entry will be used
minDist: Number - (Optional, default 0) minimum distance from the center position
maxDist: Number - (Optional, default -1) maximum distance from the center position. If -1, the world's "safePositionRadius" entry will be used
objDist: Number - (Optional, default 0) minimum distance from the resulting position to the center of nearest object. Specifying quite large distance here will slow the function and might often fail to find suitable position. Recommended value: 0..10
waterMode: Number - (Optional, default 0) water mode. Can be one of:
  • 0 - cannot be in water
  • 1 - can either be in water or not
  • 2 - must be in water
maxGrad: Number - (Optional, default 0) maximum terrain gradient (hill steepness). A quite small non-zero value could result in failure to find suitable position. Recommended: 0.1+
shoreMode: Number - (Optional, default 0) shore mode. Can be one of:
  • 0 - does not have to be at a shore
  • 1 - must be at a shore
blacklistPos: Array - (Optional, default []) list of blacklisted areas in format [area1, area2, area3... areaN]. Can be one of:
  • Array - in format [topLeftCorner, bottomRightCorner] - top and bottom coordinates of blacklisted area
  • Object - trigger area
  • String - marker area
  • Location - location
  • Array - array in format [center, distance] or [center, a, b, angle, rect] or [center, a, b, angle, rect, height]
defaultPos: Array - (Optional, default []) default position when no position is found. Array format is [landPosition, seaPosition], where:
  • landPosition: Array - in format [x,y] or [x,y,z] - default position on land
  • seaPosition: Array - in format [x,y] or [x,y,z] - default position on water
Return Value:
Array - in format [x,y] on success. When position cannot be found at all, default map center position is returned, which will be in format [x,y,0]

Examples

Example 1:
Find position minimum 1m from from player but not further than 150m, not closer than 3m to any other object, not in the water, maximum gradient of 20, not on the shoreline:
private _pos = [player, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;
Example 2:
private _pos = [getPos player, 2000, 5000, 1, 0, 0.7, 0, [], [getPos player, getPos player]] call BIS_fnc_findSafePos;
Example 3:
private _pos = [[], 0, 1000] call BIS_fnc_findSafePos;

Additional Information

See also:
BIS_fnc_randomPosTrigger BIS_fnc_randomPos

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
Killzone_Kid - c
Posted on Mar 15, 2017 - 19:30 (UTC)
To make sure position is not inside a building, increase distance to nearest object param.
AgentRev - c
Posted on Sep 24, 2021 - 22:23 (UTC)
If objDist > 0, this function will unfortunately treat all roads and trails seen on the map as obstacles to avoid, due to its unfiltered usage of nearestTerrainObjects.