Jump to content
Reverend Andy

Init scripting, If one thing spawns then another wont spawn.

Recommended Posts

I'm making an Eden mission where I have 3 compositions which I am going to place copies of each around the map, I want each type of composition to spawn a key feature for only one of the copies. 
Ex. A flag randomly spawns in only one copy of a base and not the others.
As far as randomizing item spawns I am currently using the "Object: present" slider but I'm open to any ideas on how to do that better as well. 
1 Item is a prop, 1 is a unit, 1 is a vehicle. 

I'm so sorry that this reads like a homework question but I've been smashing my head into the wall for a few days trying to get this to work and I can't seem to figure it out.
Any help would be appreciated, thank you. 

Share this post


Link to post
Share on other sites
1 hour ago, Reverend Andy said:

I'm making an Eden mission where I have 3 compositions which I am going to place copies of each around the map, I want each type of composition to spawn a key feature for only one of the copies. 
Ex. A flag randomly spawns in only one copy of a base and not the others.
As far as randomizing item spawns I am currently using the "Object: present" slider but I'm open to any ideas on how to do that better as well. 
1 Item is a prop, 1 is a unit, 1 is a vehicle. 

I'm so sorry that this reads like a homework question but I've been smashing my head into the wall for a few days trying to get this to work and I can't seem to figure it out.
Any help would be appreciated, thank you. 

Hello, Welcome to the forums! I can help you😎 What you are trying to achieve can't be done 100% with only editor tools. You MUST use script to get your desired affect. I, of course, will give you instructions and an example script that you can copy/pasta into you mission file. Make sure to click the LINKS , they have all the information you need.

 

You must create an array(3) of possible spawn locations, to choose a location at random for each of your objects spawn positions. Here is how:

 

You have 3 different compositions and you will be placing multiples of each around the map. In each of your 3 compositions, add an invisible helipad in the exact position you wish your randomized object to spawn. Name each of these invisible helipads with a specific variable name that correlates to its respective composition. 

 

Examples:

-the first compositions invisible helipad is named  "CompositionA_1",

-the second compositions invisible helipad is named  "CompositionB_1",

-the third compositions invisible helipad is named "CompositionC_1".

 

When you place multiples of variables that end in and underscore+number (EXAMPLE: CompositionA_1), for each copy of that object, the copy's variable name will be updated in a numerically sequential order (CompositionA_1,CompositionA_2,CompositionA_3....and so on).

 

After you have placed all of your compositions on the map. Add all the variable names of the invisible helipads to 3 arrays (Example below), and use the command selectRandom. Then use the selectRandom array _handle in the position parameter of the createVehicle command to create your objects. Get all that!? 🤓 Don't worry. Here's the example you can copy/pasta into your missions init.sqf (or initServer.sqf)

 

init.sqf (SinglePlayer) OR initServer.sqf (Multiplayer)

_randomSpawnPos_1 = selectRandom [CompositionA_1, CompositionA_2, CompositionA_3];
_object_1 = createVehicle ["<yourObjectClassname>", _randomSpawnPos_1, [], 0, "FORM"];

_randomSpawnPos_2 = selectRandom [CompositionB_1, CompositionB_2, CompositionB_3];
_object_2 = createVehicle ["<yourObjectClassname>", _randomSpawnPos_2, [], 0, "FORM"];

_randomSpawnPos_3 = selectRandom [CompositionC_1, CompositionC_2, CompositionC_3];
_object_3 = createVehicle ["<yourObjectClassname>", _randomSpawnPos_3, [], 0, "FORM"];

Please ask all the questions. We are happy to help!

  • Like 1

Share this post


Link to post
Share on other sites

There are always multiple ways to achive such things.

 

Another way would be without Helipads. You can just place all key features in editor and then delete all but a random one of it:

//create arrays with variable names of all objects
private _all_props = [prop1, prop2, prop3];
private _all_units = [unit1, unit2, unit3];
private _all_vehicles = [vec1, vec2, vec3];

//randomly select one object of each object type
private _left_over_prop = selectRandom _all_props;
private _left_over_unit = selectRandom _all_units;
private _left_over_vec = selectRandom _all_vehicles;

// get the inexes of the left over objects in their array
private _index_prop = _all_props findIf { _left_over_prop is EqualTo _x };
private _index_unit = _all_units findIf { _left_over_unit is EqualTo _x };
private _index_vec = _all_vecs findIf { _left_over_vec is EqualTo _x };

// delete the random selected object from their arrays
private _dummy = _all_props deleteAt _index_prop;
_dummy = _all_units deleteAt _index_unit;
_dummy = _all_vecs deleteAt _index_vec;

//merge the arrays
_all_props append _all_units;
_all_props append _all_vecs;

// delete all objects which are in the merged array yet

{ deleteVehicle _x; } count _all_props;

 

looks like a big thing but can be simplified a bit:

 

//create arrays with variable names of all objects
private _all_props = [prop1, prop2, prop3];
private _all_units = [unit1, unit2, unit3];
private _all_vehicles = [vec1, vec2, vec3];

//randomly select one object of each object type
private _left_over_prop = selectRandom _all_props;
private _left_over_unit = selectRandom _all_units;
private _left_over_vec = selectRandom _all_vehicles;

// delete the random selected objects from their arrays
private _dummy = _all_props deleteAt _all_props findIf { _left_over_prop is EqualTo _x };
_dummy = _all_units deleteAt _all_units findIf { _left_over_unit is EqualTo _x };
_dummy = _all_vecs deleteAt _all_vecs findIf { _left_over_vec is EqualTo _x };

// merge the arrays into _all_props
_all_props append _all_units;
_all_props append _all_vecs;

// delete all objects which are in the merged array yet
{ deleteVehicle _x; } count _all_props;

put in initServer.sqf ( no matter if Single- or Multiplayer ) in your missions root folder.

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

×