Jump to content
Sign in to follow this  

How to set a random start position for custom compositions

Recommended Posts

Hi guys,

maybe this was already discussed in the forums but I wasn't able to find a similar thread.

For my mission I have following plans:

-I have created a simple small tent camp of four tents in a cross shape with a small campfire in the middle

-I have created five different empty marker positions on Tanoa

-At the beginning of the mission the tent camp should spawn randomly on one of these five different marker positions or on its original placement position

For now I only get to manage to spawn all tents independently on six different locations (scattered composition) but the tent camp should stay in its composition.

Following command is great for setting random start positions of grouped NPCs so the units will stay with their group leader: {vehicle _x setpos formationposition _x} foreach units this;

I really hope there is some similar command that is working for compositions as well without the need of external scripting files (sqf-files).

Thanks in advance

Share this post

Link to post
Share on other sites

Now I am answering to myself but that is okay ;)

I was a little bit successful with trying around on different stuff.

I have found following solution for now without the need of external scripts.

1. I placed my four tents (you can rotate them as well), a campfire in a cross shape and set five different markers on random positions

2. I named the campfire -> campfire (how inventive)

3. I have marked all markers -> right click -> connect -> set random start and I clicked on the campfire
    -now the campfire is connected with all markers and will spawn on one of these (or its original) positions randomly after the mission has started

4. Now I have modified the init-line of one of the four tents with following command: this setPos [(getPos campfire select 0) + 5, (getPos campfire select 1) + 5, 0];
   -the tent will spawn five meters north and five meters east of the campfire
   -you have to change the x- and y-coordinates (e.g. -5, +10 etc.) for the other three tents so that the tents will have a relative position to the campfire (keeping the cross shape)

5. If you now start the mission the campfire will spawn randomly on one of the six position and the tents will move to the relative position of the campfire

I think this solution is okay for small compositions. But if you want to build larger compositions with more different object positions this solution is pretty time intense (because of trial and error).

So my question is: Is it possibile to create a larger composition, create a trigger around that composition and tell the trigger to move all the objects in the trigger area to my random marker positions? The moved objects should stay in its relative position to each other. The trigger area should act like a frame that you can move around on the map.

Hopefully someone else may answer ;)

Share this post

Link to post
Share on other sites

I think there's a BIS function for saving/pasting compositions but doing it manually would brobably be best like this:

  1. Name all the objects in the composition
  2. Collect the objects in an array by using nearestObjects and vehicleVarName (== "" when object isn't named)
  3. Set the center of the composition (like you did with the campfire)
  4. Create an array of arrays with this format [[relPos1, rotation1], [relPos2, rotation2]...] where relPos1 is obtained by (getPos obj1) vectorDiff (getPos center)
  5. Create a new center and paste the objects around it by using the above array (set the height to 0 and _obj1 setVectorUp surfaceNormal position _obj1; to snap it to the ground)

Share this post

Link to post
Share on other sites


Thanks for the informations. I will try these commands. I have to say that I am pretty new to scripting so it is for now really hard for me to understand.


I already have heard about this solution but thanks anyways. My target is to understand scripting and I don't want to use external scripts for my missions. This is some kind of learning progress for me ;)

  • Like 1

Share this post

Link to post
Share on other sites

KoalaDSK fair enough - I can appreciate that


Its just a 'simple' case of iterate through each object and getting the distance and bearing to each object from your central tent.

then placing them back in that orientation using the alternative syntax for 'setpos' might be a good starting point ---  setpos [distance, heading]


just remember the init fields of objects can run in the wrong order. in single player testing it might be fine, once in MP things change order and as more scripts fire off you will get some things happen out os your preferred sequence.

Share this post

Link to post
Share on other sites

So I have played around a little bit with the BIS_fnc_ObjectsGrabber command but I was just partly successful:

1. I placed a Blufor player unit, four tents, a campfire (named it campfire) in a cross shape and set three markers (named them a, b and c) on three different positions

2. I created a trigger (activation Blufor) around the camp and I have written following command in the "on activation" line (without the //):

_mycomp = [getPos campfire, 15, true] call BIS_fnc_objectsGrabber; // the compilation of four tents and the one campfire should got stored under the global variable mycomp

_pos = ["a", "b", "c"]; // defined the global variable pos for the marker positions

_startPos = pos call BIS_fnc_selectRandom; // should return one of the marker positions

0 = [(getMarkerPos startPos), 0, mycomp] call BIS_fnc_ObjectsMapper; // this should paste the "mycomp" composition on one of the three markers

4. I walked into the trigger and it happens nothing :(

What I expected was that the original camp composition got copied and is spawned on one of the three marker positions.

The only thing that is working is, that the composition is stored on the clipboard but that's it. I do not want to save the composition in a sqf-file. The composition should get stored in the _mycomp variable

Maybe one of you guys please could help me and tell me what have I done wrong?

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