shuko 59 Posted October 29, 2009 (edited) This is a random position generator/selector. It can choose a position from a marker area or by based on direction and distance from a position/object. SHK_pos.rar Marker Based Selection Required Parameters: 0 String Area marker's name. Optional Parameters: 1 Boolean Allow water positions? Default is false. 2 Array or String One or multiple blacklist area markers which are excluded from the main marker area. Position Based Selection Required Parameters: 0 Object or Position Anchor point from where the relative position is calculated from. 1 Array or Number Distance from anchor. Optional Parameters: 2 Array of Number Direction from anchor. Default is random between 0 and 360. 3 Boolean Water position allowed? Default is false. false Allow water positions. true Find closest land. Search outwards 360 degrees (20 degree steps) and 20m steps. 4 Array Road positions. 0 Number Road position forcing. Default is 0. 0 Do not search for road positions. 1 Find closest road position. Return the generated random position if none found. 2 Find closest road position. Return empty array if none found. 1 Number Road search range. Default is 200m. Usage Preprocess the file in init.sqf: call compile preprocessfile "SHK_pos\shk_pos_init.sqf"; Actually getting the position: pos = [parameters] call SHK_pos; Old version: Here's the latest version of the script Distance and direction are wrong way around in the examples! Few screenshots of the function called 500 times with different parameters Edited February 27, 2015 by Shuko Share this post Link to post Share on other sites
jw custom 56 Posted October 29, 2009 Very nice, thanks for sharing :cool: Share this post Link to post Share on other sites
dmarkwick 261 Posted October 29, 2009 Nice script :) Share this post Link to post Share on other sites
Muzza 0 Posted December 3, 2009 I am using this script to create a few positions around a user-made flare position. using onshotsfired.sqf by toasted duckie i have made a marker by firing a flare. I am trying to make others around it using your script. the SHK_pos = compile preprocessfile "SHK_pos.sqf"; for "_i" from 0 to 500 do { _p = [getpos player,random 360,random 1000] call SHK_pos; if (count _p > 0) then { call compile format [" _m%1 = createMarker[""mySpot%1"",[_p select 0,_p select 1]]; _m%1 setMarkerShape ""ICON""; _m%1 setMarkerType ""DOT""; _m%1 setmarkercolor ""colorred""; ",_i]; }; }; doesnt seem to work. I have tried ; **************************************************************** ; Script file for Armed Assault ; Created by: Toasted Duckie ; **************************************************************** _ammotype = _this select 4; // identify if the shot that was fired was a flare, if not exit the script, if it was, go find out the location and set a marker there ? _ammotype iskindof "F_40mm_Green" OR _ammotype iskindof "F_40mm_RED" OR _ammotype iskindof "F_40mm_White" OR _ammotype iskindof "F_40mm_Yellow" : goto "flare"; exit; #flare _flare = nearestObject [player, _ammotype]; ~4 _marker = createMarker ["markm203", (getpos _flare)]; _markers setMarkerShape "ICON"; "markm203" setMarkerType "DOT"; ~4 pos1 = [getmarkerpos "markm203",random 360,random 25,false,3] call SHK_pos; pos2 = [getmarkerpos "markm203",random 360,random 25,false,3] call SHK_pos; pos3 = [getmarkerpos "markm203",random 360,random 25,false,3] call SHK_pos; pos4 = [getmarkerpos "markm203",random 360,random 25,false,3] call SHK_pos; pos5 = [getmarkerpos "markm203",random 360,random 25,false,3] call SHK_pos; pos6 = [getmarkerpos "markm203",random 360,random 25,false,3] call SHK_pos; _strike1 = createMarker ["strikeloc1", (getpos pos1)]; "strikeloc1" setMarkerShape "ICON"; "strikeloc1" setMarkerType "DOT"; [] exec "airstrike2.sqf"; exit All of this. The flare creates a red marker, but nothin i can do will make any more markers. Can anyone see the problem here? Share this post Link to post Share on other sites
TRexian 0 Posted December 3, 2009 At first blush, it looks like a mix of sqs and sqf? I don't think ~ works as sleep in sqf? Also, you make _marker = createmarker, but in the next line, you use _markers (plural). Also, after the positions, instead of using "strikeLoc1", I think you need to use _strike1.... Just some quick suggestions, though. Share this post Link to post Share on other sites
shuko 59 Posted December 3, 2009 Yep, first thing people starting with scripting should be making the difference between SQS/SQF and exec/execvm clear to themselves. Anyway, here's a sqf version: _ammotype = _this select 4; if (_ammotype in ["F_40mm_Green","F_40mm_Red","F_40mm_White","F_40mm_Yellow"]) then { if (isnil "SHK_pos") then { SHK_pos = compile preprocessfile "SHK_pos.sqf" }; _flare = nearestObject [player, _ammotype]; sleep 4; _marker = createMarker ["markm203", (getpos _flare)]; _marker setMarkerShape "ICON"; _marker setMarkerType "DOT"; sleep 1; for "_i" from 1 to 6 do { _p = [getmarkerpos _marker,random 360,random 25,false,3] call SHK_pos; if (count _p > 0) then { call compile format [" _m%1 = createMarker[""strikeloc%1"",_p]; _m%1 setMarkerShape ""ICON""; _m%1 setMarkerType ""DOT""; _m%1 setmarkercolor ""colorred""; ",_i]; }; }; [] exec "airstrike2.sqf"; // exec is for sqs files not sqf, however I have feeling the code used in it is actually sqs }; Tested with a unit which had this in init field: this addEventHandler ["fired",{_this execvm "onshotsfired.sqf"}]; Share this post Link to post Share on other sites
shuko 59 Posted March 15, 2011 Working on a new, completely rewritten, version. Just finished relearning some trigonometry. 500 random positions (green dots) picked from blue marker area. Red areas are blacklist markers. Same as above, but the water parameter was changed so that it doesn't allow positions where surface is water. Share this post Link to post Share on other sites
demonized 20 Posted March 15, 2011 very nice Shuko. Share this post Link to post Share on other sites
shuko 59 Posted March 17, 2011 (edited) More math lessons. Position selection from an ellipse avoiding Gimbal lock (uneven distribution). With a blacklist and water filter. Edited March 17, 2011 by Shuko Share this post Link to post Share on other sites
shuko 59 Posted March 17, 2011 Circle markers this time. :) Share this post Link to post Share on other sites
mosh 0 Posted March 17, 2011 Awesome, nice job... something else I can use. Thanks yet again! :) Share this post Link to post Share on other sites
shuko 59 Posted March 24, 2011 Version 0.2 Let the bug reports flow. :) Share this post Link to post Share on other sites
Lonestar 11 Posted March 24, 2011 How can I use this script to generate random positions for a specific faction? Share this post Link to post Share on other sites
shuko 59 Posted March 24, 2011 It's just a function to pick a random position. It doesn't depend on side, unit or faction etc. It's up to you how you use it in scripts. Example, move all marines to random positions within a marker: { if (faction _x == "USMC") then { _p = "markerName" call SHK_pos; _x setpos _p; }; } foreach allunits; Share this post Link to post Share on other sites
Lonestar 11 Posted March 24, 2011 Thanks Shuko. :smile: Share this post Link to post Share on other sites
Antigoon 10 Posted March 24, 2011 This seems to be really helpfull script, however I'm unsure how to set it up. Suppose I have some enemy groups inside houses in zargabad...when a trigger fires I want them to spread out in the city (marker covering entire city), but not always in the same exact position. Your script seems like the perfect solution to randomise their destinations and positions in the city. My thinking is to execute a script when the trigger fires and inside that have all the groups move to their random positions using your script. How could I get this working? Share this post Link to post Share on other sites
shuko 59 Posted March 24, 2011 (edited) Something like this I guess. { _p = "CityMarker" call SHK_pos; _x move _p; } foreach [grp1,grp2,grp3]; Edited March 24, 2011 by Shuko Share this post Link to post Share on other sites
Antigoon 10 Posted March 24, 2011 I tried it and the units always move to the southwest corner of the map! I'm not using a marker that's used by another script (I read somewhere that UPSMON moves it's markers). Don't know what's going on there... Share this post Link to post Share on other sites
shuko 59 Posted March 24, 2011 I changed the code a bit, instead of units it takes the groups straight away. Share this post Link to post Share on other sites
Antigoon 10 Posted March 24, 2011 No luck, units still always move to the bottom SW corner of the map. It's as if the marker was moved there.... Share this post Link to post Share on other sites
shuko 59 Posted March 24, 2011 http://derfel.org/arma2/_antigoon_shk_pos.utes.rar The code above and the script both work. I don't have a crystal ball to tell you what's wrong with your marker. Share this post Link to post Share on other sites
Guest Posted March 24, 2011 (edited) No units move at all for me:confused: I have this code in randomized.sqf { _p = "randomusmkr1" call SHK_pos; _x move _p; } foreach [unit1,unit2]; which gets called by a trigger like this: null=[] execVM "randomized.sqf"; When the trigger activates, nobody gets put inside the marker, they just stay in the same position. I am using upsmon script so dunno if that has anything to do with it? EDIT: I'll try out that test mission above. EDIT2: I'm an idiot, I forgot about the call compile preprocessfile "SHK_pos\shk_pos_init.sqf"; Edited March 24, 2011 by Guest Share this post Link to post Share on other sites
Antigoon 10 Posted March 24, 2011 (edited) The code above and the script both work. I don't have a crystal ball to tell you what's wrong with your marker. No worries, Shuko. Thx for taking the time to help me, it's much appreciated. I'll twiddle around with it some more to get it to work. Your example will be helpfull, thx! EDIT: I got it working with the code from your example, thx again Edited March 24, 2011 by Antigoon Share this post Link to post Share on other sites
Guest Posted March 24, 2011 How would one go about randomizing objects? I would like some crates to be placed randomly within a marker area. Share this post Link to post Share on other sites
shuko 59 Posted March 24, 2011 We already had a few examples, crates would work exactly same way: { _x setpos ("marker" call SHK_pos) } foreach [create1,create2]; Share this post Link to post Share on other sites