OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Resources Beta Testing & Submission => Topic started by: Shuko on 07 Nov 2009, 20:48:08

Title: SHK_pos - Random position generator *ACCEPTED*
Post by: Shuko on 07 Nov 2009, 20:48:08
Random position generator, from an marker area or desired direction and distance with water position handling.

Download (http://www.ofpec.com/ed_depot/index.php?action=details&id=651)

Few screenshots of the function called 500 times with different parameters (http://derfel.org/arma2/scripts/pos/img)

Code: [Select]
 Parameters for marker area based position:
    Area              String              Marker to define area from which the position is taken.
    Water             Boolean             Allow position on water? Optional, default is false.
  
  Usage examples:
    myPos = ["markerName"] execvm "SHK_pos.sqf";
    myPos = ["myMarker1",true] execvm "SHK_pos.sqf";
    
  Parameters for relative position:
    Point of Origin   Position array      The position from which direction and distance is calculated from.
    Direction         Number              Compass direction (0-359) from Point of Origin.
                      Array               Array can be used to give minimum and maximum directions.
    Distance          Number              Distance in meters from Point of Origin.
                      Array               Array can be used to give minimum and maximum distance.
    Water             Boolean             Allow position on water? Optional, default is false.
    Water solution    Integer             Water positions not allowed, what to do?
      0: Do nothing, do not return any position. An empty array is returned.
      1: Find closest land. Search is done with increasing radius until land is found, thus the resulting
         position might not be exactly in the given direction and distance.
      2: Decrease distance until land is found. Direction is kept the same.
      3: Increase distance until land is found. Direction is kept the same.
      4: Decrease direction (counter clock-wise) until land is found. Distance is kept the same.
      5: Increase direction (clock-wise) until land is found. Distance is kept the same.
      
      If no integer is given, solution 1 is used by default.
  
  Usage examples:
    myPos = [getpos player,random 360,200,true] execvm "SHK_pos.sqf";
    myPos = [getmarkerpos "myMarker",125,random 500] execvm "SHK_pos.sqf";
    myPos = [getpos player,random 360,[200,500],false,2] execvm "SHK_pos.sqf";
  
  Example of creating multiple positions:
    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];
      };
    };

Download (http://www.ofpec.com/ed_depot/index.php?action=details&id=651)
Title: Re: SHK_pos - Random position generator
Post by: i0n0s on 07 Nov 2009, 22:08:22
If you add the readme to the archive, the resource would be ready for submitting.

I would also recommend to advertice the purpose of the script more. E.g. for animals/units FSM, to calculate a random point within an area, then to calculate a point away from a unit.

Next step would just to check if there is a easy connection between points and that no water is between. But this would cost too much CPU time.
Title: Re: SHK_pos - Random position generator
Post by: Shuko on 08 Nov 2009, 00:23:41
Added the readme, but couldn't really think of anything to add to it apart from the parameters. Same goes with the advertisement, all it does is pick random position, people can use it to whatever they can think of. For example, I've made a defense mission where you can use parameters to pick enemy attack direction, distance, sector width etc.

Another one I made is one where you can train navigation (orienteering) by randomly placing control points which players need to find by using just map and compass. One use I've found for it is that if you need to move/place multiple objects/units to a position, you can just do random 360 for direction and something like 5-15 for distance. That way they will be placed near the position but without being right on top of each other (can injure units when moving a group). Simple, no need to start tinkering with +/- couple of meters for each x and y.

The script isn't anything fancy, I just needed random positions so I made this. Thought Id share it.