BIS fnc randomPos: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\|gr([0-9]+) = " to "|gr$1= ")
m (Text replacement - "(Optional, default {{hl|[]}})" to "(Optional, default <sqf inline>[]</sqf>)")
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{RV|type=function
{{RV|type=function


| game2= arma3
|game1= tkoh
|version2= 1.00|VERSION2=
|version1= 1.00


|TKOH
|game2= arma3
|1.00
|version2= 0.50


|gr1= Map and Markers
|gr1= Positions
| Selects random position according to given params within given area


| [whitelist, blacklist, code] call '''BIS_fnc_randomPos'''
|descr= Selects random position according to given params within given area


|p1= [whitelist, blacklist, code]: [[Array]]
|s1= [whitelist, blacklist, code] call [[BIS_fnc_randomPos]]
|p2=whitelist (Optional): [[Array]] - whitelisted areas. If not given, whole map is used. Areas could be:
 
|p1= whitelist: [[Array]] - whitelisted areas. If not given, whole map is used. Areas can be:
* [[Object]] - trigger
* [[Object]] - trigger
* [[String]] - marker
* [[String]] - marker
* [[Array]] - in format [center, radius] or [center, [a, b, angle, rect]]
* [[Array]] - in format [center, radius] or [center, [a, b, angle, rect]]
* [[Location]] - location.
* [[Location]] - location
|p3=blacklist (Optional): [[Array]] - blacklisted areas. If not given, water is blacklisted. Areas could be:
 
|p2= blacklist: [[Array]] - (Optional, default <sqf inline>[]</sqf>) blacklisted areas. If not given, water is blacklisted. Areas can be:
* [[Object]] - trigger
* [[Object]] - trigger
* [[String]] - marker name or special tags names: "water" - exclude water, "ground" - exclude land
* [[String]] - marker name or special tags names: "water" - exclude water, "ground" - exclude land
* [[Array]] - in format [center, radius] or [center, [a, b, angle, rect]]
* [[Array]] - in format [center, radius] or [center, [a, b, angle, rect]]
* [[Location]] - location.
* [[Location]] - location
|p4= code (Optional): [[Code]] - 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
 
|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


|[[Array]] - position candidate in format [x,y,z] or [0,0] if position cannot be found
|r1= [[Array]] - position candidate in format [x,y,z] or [0,0] if position cannot be found


|x1= <code>_randomPosMapNoWater = [] [[call]] [[BIS_fnc_randomPos]];</code>
|x1= <sqf>private _randomPosMapNoWater = [] call BIS_fnc_randomPos;</sqf>
|x2= <code>_randomPosMapNoWater = [<nowiki/>[[nil]], ["water"]] [[call]] [[BIS_fnc_randomPos]];</code>
|x3= <code>_randomPosMapNoLand = [<nowiki/>[[nil]], ["ground"]] [[call]] [[BIS_fnc_randomPos]];</code>
|x4= <code>_randomPosMap = [<nowiki/>[[nil]], []] [[call]] [[BIS_fnc_randomPos]];</code>
|x5= <code>_randomPosAroundPlayer = <nowiki>[[[</nowiki>[[position]] [[player]], 50]],[]] [[call]] [[BIS_fnc_randomPos]];</code>


|seealso= [[BIS_fnc_randomPosTrigger]], [[BIS_fnc_getArea]], [[BIS_fnc_findSafePos]]
|x2= <sqf>private _randomPosMapNoWater = [nil, ["water"]] call BIS_fnc_randomPos;</sqf>
}}


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


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


[[Category:{{Name|tkoh}}: Functions|{{uc:randomPos}}]]
|x5= <sqf>private _randomPosAroundPlayer = [[[position player, 50]], []] call BIS_fnc_randomPos;</sqf>


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


<dl class="command_description">
{{Note
<dt></dt>
|user= Tankbuster
<dd class="notedate">Posted on March 30, 2020 - 21:33 (UTC)</dd>
|timestamp= 20200330213300
<dt class="note">[[User:Tankbuster|Tankbuster]]</dt>
|text= The code parameter here can be quite powerful.
<dd class="note">
If using {{Link|#Example 5}} above, adding code as below will make the returned positions always be on a road.
The code parameter here can be quite powerful.
<sqf>private _randomRoadPosAroundPlayer = [[[position player, 50]], [], { isOnRoad _this }] call BIS_fnc_randomPos;</sqf>
If using example 5 above, adding code as below will make the returned positions always be on a road.
}}
<code>randomRoadPosAroundPlayer = <nowiki>[[[</nowiki>[[position]] [[player]],50]],[], {[[isOnRoad]] _this}] [[call]] [[BIS_fnc_randomPos]];</code>
</dd>
</dl>

Latest revision as of 18: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;