M1ke_SK 230 Posted September 18, 2015 I am using BIS_fnc_randomPosTrigger (https://community.bistudio.com/wiki/BIS_fnc_randomPosTrigger) for random position in trigger area. How can I get random position for marker area assuming that marker is circle/rectangle? Share this post Link to post Share on other sites
HallyG 239 Posted September 18, 2015 This is stripped from a function of mine, which I use for random positions: params [ ["_centre", objNull, [objNull, []]], ["_radius", 50, [0]], ["_dir", random 360, [0]], ["_height", 0, [0]] ]; if (typename _centre == "OBJECT") then { _centre = getpos _centre; }; [(_centre select 0) + (sin _dir *_radius), (_centre select 1) + (cos _dir *_radius), _height] Share this post Link to post Share on other sites
twisted 128 Posted September 18, 2015 another option is shk_pos - a pretty damn nice script. http://www.armaholic.com/page.php?id=22316 Share this post Link to post Share on other sites
Joe98 92 Posted September 18, 2015 Place a marker on the map, give it a radius of say 200 meters. Place a watch on the map. Name it watch1. Give it a radius of 200 meters. Place the watch exactly over the marker. Name your soldier blue1. Now write a command: blue1 setpos getpos watch1 ============================================================ The watch will start at a random location within the marker area. The soldier will start by standing on the watch. That is, he will appear at a random location within the marker. (Sometimes an AI soldier will see the watch and report that he sees an object. In the init of the watch type hideobject this; and the watch becomes invisible). . 1 Share this post Link to post Share on other sites
SilentSpike 84 Posted September 18, 2015 I recently wrote a function for this and it's in CBA :) https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_randPosArea.sqf Wasn't aware of that BIS command, that's really badly named :P Share this post Link to post Share on other sites
Larrow 2822 Posted September 20, 2015 _mrk = "myMarker"; _area = markerSize _mrk; _nul = _area pushBack markerDir _mrk; _nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" ); pos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger; Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 14, 2017 On 9/20/2015 at 9:19 PM, Larrow said: _mrk = "myMarker"; _area = markerSize _mrk; _nul = _area pushBack markerDir _mrk; _nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" ); pos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger; Thank you very much Larrow. I know this is a pretty old thread, but could you please show me the way to somehow incorporate safepos in this to safely spawn vehicles within a marker at random spots? Oh and btw, I am using your script for the following spawn function and its causing a tremendous amount of lag. What gives? The call line is: [20,3,2,0,0] spawn fnc_patrols; fnc_patrols = { _numFootPatrols = _this select 0; _numVehPatrols = _this select 1; _numArmorPatrols = _this select 2; _numMechPatrols = _this select 3; _numAirPatrols = _this select 4; _footUnits = ["BUS_InfSentry", "BUS_InfTeam", "BUS_InfTeam_AT", "BUS_InfSquad","BUS_SniperTeam"]; _vehUnits = ["B_MRAP_01_hmg_F","B_MRAP_01_gmg_F"]; _armorUnits = ["B_MBT_01_cannon_F","B_MBT_01_arty_F","B_APC_Tracked_01_rcws_F","B_APC_Tracked_01_CRV_F"]; _mechUnits = ["B_APC_Wheeled_01_cannon_F","B_APC_Tracked_01_AA_F"]; _airUnits = ["B_Heli_Light_01_armed_F","B_Heli_Transport_01_camo_F","B_Heli_Attack_01_F"]; _center = createCenter WEST; _mrk = "m1"; _pos = getMarkerpos _mrk; _area = getMarkerSize _mrk; for "_i" from 1 to _numFootPatrols do { _configGrp = _footUnits call BIS_fnc_selectRandom; _nul = _area pushBack markerDir _mrk; _nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" ); _rndPos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger; //_rndPos = [_pos, 1, (_area select 0), 2, 0, 30, 0, [],[_pos]] call BIS_fnc_findSafePos; _grp = [_rndPos, _center, (configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> (_configGrp))] call BIS_fnc_spawnGroup; [_grp, getMarkerPos "m2"] call BIS_fnc_taskAttack; {_x enableStamina false;} forEach units _grp; sleep 0.5; [_grp,_rndPos] spawn { _gp = _this select 0; _rndPos = _this select 1; while {true} do { sleep 6; if (({(alive _x)} count (units _gp)) < 1) exitWith { deleteGroup _gp; [1, 0, 0, 0, 0] call fnc_patrols }; }; }; sleep 0.05; }; for "_i" from 1 to _numVehPatrols do { _nul = _area pushBack markerDir _mrk; _nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" ); _rndPos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger; //_rndPos = [_pos, 1, (_area select 0), 2, 0, 30, 0, [],[_pos]] call BIS_fnc_findSafePos; _configGrp = selectRandom _vehUnits; _patrolVeh = createVehicle [_configGrp, _rndPos, [], 0, "NONE"]; createVehicleCrew _patrolVeh; _group = group _patrolVeh; [_group, _pos] call BIS_fnc_taskAttack; sleep 0.5; [_group,_rndPos] spawn { _gp = _this select 0; _rndPos = _this select 1; while {true} do { sleep 6; if (({(alive _x)} count (units _gp)) < 1) exitWith { deleteGroup _gp; [0, 1, 0, 0, 0] call fnc_patrols }; }; }; sleep 0.5; }; for "_i" from 1 to _numArmorPatrols do { _nul = _area pushBack markerDir _mrk; _nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" ); _rndPos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger; //_rndPos = [_pos, 1, (_area select 0), 2, 0, 30, 0, [],[_pos]] call BIS_fnc_findSafePos; _configGrp = selectRandom _armorUnits; _patrolVeh = createVehicle [_configGrp, _rndPos, [], 0, "NONE"]; createVehicleCrew _patrolVeh; _group = group _patrolVeh; [_group, _pos] call BIS_fnc_taskAttack; sleep 0.5; [_group,_rndPos] spawn { _gp = _this select 0; _rndPos = _this select 1; while {true} do { sleep 6; if (({(alive _x)} count (units _gp)) < 1) exitWith { deleteGroup _gp; [0, 0, 1, 0, 0] call fnc_patrols }; }; }; sleep 0.5; }; }; Thanks again. :) Share this post Link to post Share on other sites
Larrow 2822 Posted November 15, 2017 12 hours ago, ArmaMan360 said: Thank you very much Larrow. There have been a few changes to BI's functions since this thread, you can now just pass the marker name without having to specify the extra params. 12 hours ago, ArmaMan360 said: could you please show me the way to somehow incorporate safepos in this Once you have the position returned from BIS_fnc_randomPosTrigger, just use this in your call to BIS_fnc_findSafePos, the params needed are explained on the functions wiki page, TBH I very rarely use the function so maybe someone else can help you out. 12 hours ago, ArmaMan360 said: its causing a tremendous amount of lag Well could be a number of things. Is it constant lag or only for the first couple of minutes after the function spawns its AI? You create 25 groups of various size all within 0.05 seconds of each other. Maybe spread them out a little. You also create 25 threads in the scheduler. Use a Killed EH instead. _grp setVariable[ "callBack", [ 1, 0, 0, 0, 0 ] ]; //fnc_patrols params { _x addEventHandler [ "Killed", { params[ "_killed" ]; if ( { alive _x }count units group _killed isEqualTo 0 ) then { _callBack = group _killed getVariable "callBack"; deleteGroup group _killed; _callBack call fnc_patrols; }; }]; }forEach units _grp; Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 15, 2017 1 hour ago, Larrow said: _grp setVariable[ "callBack", [ 1, 0, 0, 0, 0 ] ]; //fnc_patrols params { _x addEventHandler [ "Killed", { params[ "_killed" ]; if ( { alive _x }count units group _killed isEqualTo 0 ) then { _callBack = group _killed getVariable "callBack"; deleteGroup group _killed; _callBack call fnc_patrols; }; }]; }forEach units _grp; By the way Larrow, I am using this inside a "for "_i" from...." line and towards the end there is a sleep of .6 seconds before the next loop. However it's giving me a "Generic error in expression." message. This is the snippet from the sqf: for "_i" from 1 to _numFootPatrols do { _configGrp = _footUnits call BIS_fnc_selectRandom; _rndPos = [_pos, 1, (_area select 0), 2, 0, 30, 0, [],[_pos]] call BIS_fnc_findSafePos; _grp = [_rndPos, _center, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> (_configGrp))] call BIS_fnc_spawnGroup; [_grp, getMarkerPos "m1"] call BIS_fnc_taskAttack; {_x enableStamina false;} forEach units _grp; sleep 0.5; _grp setVariable[ "callBack", [ 1, 0] ]; //fnc_patrols params { _x addEventHandler [ "Killed", {params[ "_killed" ]; if ( { alive _x }count units group _killed isEqualTo 0 ) then { _callBack = group _killed getVariable "callBack"; deleteGroup group _killed; _callBack call fnc_patrols2; }; }]; }forEach units _grp; sleep 0.6; // generic error here }; Thanks Share this post Link to post Share on other sites