BIS fnc randomPos: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (1 revision)
m (Text replacement - "(Optional, default {{hl|[]}})" to "(Optional, default <sqf inline>[]</sqf>)")
 
(46 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{RV|type=function


{{Function|= Comments
|game1= tkoh
____________________________________________________________________________________________
|version1= 1.00


| tkoh |= Game name
|game2= arma3
|version2= 0.50


|1.00|= Game version
|gr1= Positions
____________________________________________________________________________________________


| <pre>/*
|descr= Selects random position according to given params within given area


Description:
|s1= [whitelist, blacklist, code] call [[BIS_fnc_randomPos]]
Selects random position of given params within given area


Parameter(s):
|p1= whitelist: [[Array]] - whitelisted areas. If not given, whole map is used. Areas can be:
_this select 0 (Optional): ARRAY - whitelist of elements:
* [[Object]] - trigger
ARRAY - [center,radius]
* [[String]] - marker
OBJECT - trigger
* [[Array]] - in format [center, radius] or [center, [a, b, angle, rect]]
STRING - one of following tags:
* [[Location]] - location
"water" - all water surfaces
"ground" - all ground surfaces
"out" - area outside of map area
Default value - map area
_this select 1 (Optional): ARRAY - blacklist (same rules are for whitelist)
Default value: ["water","out"]
_this select 2 (Optional): CODE - custom condition


Returns:
|p2= blacklist: [[Array]] - (Optional, default <sqf inline>[]</sqf>) blacklisted areas. If not given, water is blacklisted. Areas can be:
ARRAY - [x,y,z]
* [[Object]] - trigger
*/
* [[String]] - marker name or special tags names: "water" - exclude water, "ground" - exclude land
* [[Array]] - in format [center, radius] or [center, [a, b, angle, rect]]
* [[Location]] - location


|p3= code: [[Code]] - (Optional, default <sqf inline>{ true }</sqf>) custom condition which should return true for current position candidate passed in [[Magic Variables#this|_this]] variable to be accepted. If not specified all candidates are accepted


</pre><small>''(Placeholder description extracted from the function header by [[BIS_fnc_exportFunctionsToWiki]])''</small> |= Description
|r1= [[Array]] - position candidate in format [x,y,z] or [0,0] if position cannot be found
____________________________________________________________________________________________


| <!-- [] call [[BIS_fnc_randomPos]]; --> |= Syntax
|x1= <sqf>private _randomPosMapNoWater = [] call BIS_fnc_randomPos;</sqf>


|p1= |= Parameter 1
|x2= <sqf>private _randomPosMapNoWater = [nil, ["water"]] call BIS_fnc_randomPos;</sqf>


| |= Return value
|x3= <sqf>private _randomPosMapNoLand = [nil, ["ground"]] call BIS_fnc_randomPos;</sqf>
____________________________________________________________________________________________


|x1= <code></code> |=
|x4= <sqf>private _randomPosMap = [nil, []] call BIS_fnc_randomPos;</sqf>
____________________________________________________________________________________________


| |= See also
|x5= <sqf>private _randomPosAroundPlayer = [[[position player, 50]], []] call BIS_fnc_randomPos;</sqf>


|seealso= [[BIS_fnc_randomPosTrigger]] [[BIS_fnc_getArea]] [[BIS_fnc_findSafePos]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= Tankbuster
<!-- Note Section BEGIN -->
|timestamp= 20200330213300
 
|text= The code parameter here can be quite powerful.
<!-- Note Section END -->
If using {{Link|#Example 5}} above, adding code as below will make the returned positions always be on a road.
</dl>
<sqf>private _randomRoadPosAroundPlayer = [[[position player, 50]], [], { isOnRoad _this }] call BIS_fnc_randomPos;</sqf>
 
}}
<h3 style="display:none">Bottom Section</h3>
[[Category:Function Group: Map|{{uc:randomPos}}]]
[[Category:Functions|{{uc:randomPos}}]]
[[Category:{{Name|tkoh}}: Functions|{{uc:randomPos}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:randomPos}}]]

Latest revision as of 19:09, 8 November 2023

Hover & click on the images for description

Description

Description:
Selects random position according to given params within given area
Execution:
call
Groups:
Positions

Syntax

Syntax:
[whitelist, blacklist, code] call BIS_fnc_randomPos
Parameters:
whitelist: Array - whitelisted areas. If not given, whole map is used. Areas can be:
blacklist: Array - (Optional, default []) blacklisted areas. If not given, water is blacklisted. Areas can be:
  • Object - trigger
  • String - marker name or special tags names: "water" - exclude water, "ground" - exclude land
  • Array - in format [center, radius] or [center, [a, b, angle, rect]]
  • Location - location
code: Code - (Optional, default { true }) custom condition which should return true for current position candidate passed in _this variable to be accepted. If not specified all candidates are accepted
Return Value:
Array - position candidate in format [x,y,z] or [0,0] if position cannot be found

Examples

Example 1:
private _randomPosMapNoWater = [] call BIS_fnc_randomPos;
Example 2:
private _randomPosMapNoWater = [nil, ["water"]] call BIS_fnc_randomPos;
Example 3:
private _randomPosMapNoLand = [nil, ["ground"]] call BIS_fnc_randomPos;
Example 4:
private _randomPosMap = [nil, []] call BIS_fnc_randomPos;
Example 5:
private _randomPosAroundPlayer = [[[position player, 50]], []] call BIS_fnc_randomPos;

Additional Information

See also:
BIS_fnc_randomPosTrigger BIS_fnc_getArea BIS_fnc_findSafePos

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
Tankbuster - c
Posted on Mar 30, 2020 - 21:33 (UTC)
The code parameter here can be quite powerful. If using Example 5 above, adding code as below will make the returned positions always be on a road.
private _randomRoadPosAroundPlayer = [[[position player, 50]], [], { isOnRoad _this }] call BIS_fnc_randomPos;