Jump to content
Storm Rider

Random Plant Generator script or module?

Recommended Posts

Hello lads, I'm trying to figure out how I can randomly generate a random array of objects in a given area. I would like to increase the density of vegetation of a given forested area without the need to manually place each tree or plant individually. I'd like to be able to input an array of objects, a amount and a marker area, have it to randomly pick and distribute these objects inside this area. Anyone has any idea on how to achieve this?  I thinking about these two sources:

 

https://community.bistudio.com/wiki/Example_Code:_Random_Area_Distribution

 

Cheers

 

 

 

 

Share this post


Link to post
Share on other sites

There is no vegetation object (no class for createVehicle), if I'm right, in Arma vanilla. So, are you using CUP mod, or else, for that?
or do you want to stay in Arma vanilla? In this case you can try the createSimpleObject command with model info.

 

Note:

It's easy to create vegetation as simple objects. You can save CPU resource but the trees, bushes or any little plant is not destroyable. That's a nightmare even for tanks.

On the other hand, if you create many bushes with createVehicle on existing class (like in CUP), your FPS could dramatically drop.

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

There is no vegetation object (no class for createVehicle), if I'm right, in Arma vanilla. So, are you using CUP mod, or else, for that?
or do you want to stay in Arma vanilla? In this case you can try the createSimpleObject command with model info.

 

Note:

It's easy to create vegetation as simple objects. You can save CPU resource but the trees, bushes or any little plant is not destroyable. That's a nightmare even for tanks.

On the other hand, if you create many bushes with createVehicle on existing class (like in CUP), your FPS could dramatically drop.

Thank you Pierre. I'm using SOG Prairie Fire CDLC. I tried it already using a clumsy combination of tools and modules like "Eden Extended Objects" to generate a bunch of random objects and "Terrain Object Replacement Module" to replace the created objects with a random selection of plants and trees. The loading times increased a lot, but it didn't affect performance too much, I think manly because it's only creating these objects in a small area and not the entire map.

 

Regarding simpleobjects, do they affect line of sight of AI? The worst case scenario would be to have plants that limit a player's view but not the AI.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Bah, I tested with SOG PF objects, extracted classes with:
_allConfVeg = "getText (_x / 'vehicleClass') == 'vn_vegetation'" configClasses (configFile / "cfgVehicles");

_allClassVeg = _allConfVeg apply {configName _x};

then created some in a trigger area, with createVehicle .... There is no added value. The vegetation is in steel! blocking any tank.

 

So, falling back on simple objects...

You can script something with a marker (named here "mk1", or a trigger name of your choise), a vegetation population of 600 (here)

 

MGI_allConfVeg = "getText (_x / 'vehicleClass') == 'vn_vegetation'" configClasses (configFile / "cfgVehicles");
MGI_allModelVeg = MGI_allConfVeg apply {getText (_x / "model")};
 
0 = ["mk1",600,TRUE] spawn {
  params ["_area",["_count",1],["_simple",TRUE]];
  private _veg = "";
  private _posOrig = [0,0,0];
  private _pos = +_posOrig;
  private _maxRadius = worldSize;
  call {
    if (_area isEqualType "" && {_area in allMapMarkers}) exitWith {
      _posOrig = markerPos _area;
      _maxRadius = sqrt ((markerSize _area #0) ^2 + (markerSize _area #1)^2);
    };
    if (_area isEqualType objNull && {_area isKindOf "emptyDetector"}) exitWith {
      _posOrig = getPos _area;
      _maxRadius = sqrt ((triggerArea _area #0) ^2 + (triggerArea _area #1)^2);
    };
  };
  if (_maxRadius == worldSize) exitWith {systemChat "too wide area! check your parameters..."};
  
  private ["_modelVeg","_veg"];
  for "_i" from 1 to _count do {
    _modelVeg = selectRandom MGI_allModelVeg;
    while {_pos = _posOrig getPos [sqrt random 1 * _maxRadius,random 360]; !(_pos inArea _area)} do {_pos = _posOrig};
    _veg = createSimpleObject [_modelVeg,_pos];
    _veg setPosWorld (ATLToASL _pos vectorAdd ((getPos _veg vectorDiff (_veg modelToWorld [0,0,0])) vectorMultiply 0.9));
    _veg setDir random 360;
  };  
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Really cool pierremgi, that worked reasonable well, but there was a few problems.

 

First, there were some objects floating in the air, such a dead fallen tress, and tree stumps. 

Second, there are a number of objects that would been to be removed from the list, such as the Christmas Tree, and rice plants that form perfect squares for the rice paddies. 

Share this post


Link to post
Share on other sites
8 hours ago, stburr91 said:

Really cool pierremgi, that worked reasonable well, but there was a few problems.

 

First, there were some objects floating in the air, such a dead fallen tress, and tree stumps. 

Second, there are a number of objects that would been to be removed from the list, such as the Christmas Tree, and rice plants that form perfect squares for the rice paddies. 

 

First:  I can't do anything for bad (specific) model dimensions. CreateSimpleObject is not very cool for object positioning. I applied a standard offset (adding vector) of ((getPos _veg vectorDiff (_veg modelToWorld [0,0,0])) vectorMultiply 0.9))  All you can do is testing different vector multiplication from 0 to ...  I decided 0.9 as a way to hide most the the tree root into the ground.  But this correction (offset) applies to all objects. We can script specific offset for specific objects but that demands multiple testings.

 

Second: if you don't want some objects, find their models (point at them in preview and  getModelInfo cursorObject #1 will return the  path to remove from the MGI_allModelVeg (once defined). So you can remove a kind of black listed model paths from this array.

(I'll not doing that but feel free to share your blacklist!) Thanks.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×