Jump to content
Sign in to follow this  
tommytom1

Setting random scale for all IsKindOf objects

Recommended Posts

mossRocks = [

    "Land_RM_boulder1",

    "Land_Cliff_stone_small_F",

    "Land_Cliff_stone_medium_F",

    "Land_Cliff_stone_big_F",

    "Land_RM_boulder5",

    "Land_RM_boulder4",

    "Land_RM_boulder3",

    "Land_RM_boulder2"

];

 

{

    _objectType = typeOf _x;

    if (_objectType isKindOf mossRocks) then {

        _scale = selectRandom [0.9, 1.4];

        _x setObjectScale _scale;

    };

} forEach mossRocks;

im trying to pick a random number between 0.9 and 1.4 and have it set Scale for all my lil mossy rocks in my mission

im doing this from the init.sqf and from some reason it doesn't work is there any obvious errors in the code im missing? (probably:D)

Share this post


Link to post
Share on other sites

Your code won't do anything because you're not running it on any object : your mossRocks array is holding classnames, not objects.

 

But before we dig into the syntax errors, you should know that you can't modify terrain objects; if the idea is to adjust the size of all those objects on the terrain, the process is going to be a bit more involved :

- you'll need to detect all corresponding terrain object and hide them. And then spawn the same model with a random size - spawn them as simple objects to do so.

- buuuuut, the sheer number of objects to keep in memory will most likely be enough to crash the game while attempting to save in SP, and/or cause many issues in MP.

  • Like 2

Share this post


Link to post
Share on other sites

Are these rocks placed by you in the mission or are they terrain objects as @haleks mentioned? SP or MP? More details = more better.

 

Assuming they are objects placed in Eden by you, something like this:

mossRocks = [
	"Land_RM_boulder1",
	"Land_Cliff_stone_small_F",
	"Land_Cliff_stone_medium_F",
	"Land_Cliff_stone_big_F",
	"Land_RM_boulder5",
	"Land_RM_boulder4",
	"Land_RM_boulder3",
	"Land_RM_boulder2"
];

{
	_objectType = typeOf _x;
	
	if (_objectType in mossRocks) then {
		_scale = selectRandom [0.9, 1.4];
		_x setObjectScale _scale;
	};

} forEach allMissionObjects;

 

 

But this is inefficient at best, as we are iterating through all mission objects. 

 

Better would be to place your rock objects in their own Eden layer (for example, a layer named "Rocks") then just iterate through that:

{
	_scale = selectRandom [0.9, 1.4];
	_x setObjectScale _scale;
} forEach getMissionLayerEntities "Rocks" #0;

 

Share this post


Link to post
Share on other sites

Oh, you are also just picking one of your two values, not from the range between them. That's what selectRandom does. You should use random instead:

_scale = random [0.9, 1.15, 1.4];

But this will result in values weighted toward the center, so you will see fewer of the larger and smaller rocks.

 

This:

_scale = ((floor random 6)+9)/10;

will give you a relatively even distribution of values between 0.9 and 1.4.

 

Both of the above will return values to five places (e.g. 1.12345).

 

If you only want values to one decimal place, you can use BIS_fnc_cutDecimals:

_scale = [random [0.9, 1.15, 1.4], 1] call BIS_fnc_cutDecimals;

// OR

_scale = [((floor random 6)+9)/10, 1] call BIS_fnc_cutDecimals;

 

I'm sure there are other ways that might even be better, but these work.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

thanks alot @Harzach , it works perfectly ! i didnt know about getMissionLayerEntities which just opened a door full of possibilities so cool. 

this works fine, thanks everyone

_scale = [random [0.9, 1.15, 1.4], 1] call BIS_fnc_cutDecimals;

{

    _x setObjectScale _scale;

} forEach getMissionLayerEntities "Rocks" #0;

hint "Rock on";

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
Sign in to follow this  

×