Jump to content
Sign in to follow this  
jackrabbitslim7

Placement radius for several groups

Recommended Posts

Hi all,

I would like to know if it's possible to spawn different groups randomly but together. If I set a random position for each group they'll not spawn all at the same place, I tried using the getpos setpos command, but as a tank is being used it spawns right on top of my head, I'd prefer it to spawn a few meters from me. The command I'm using is this one : "unit" setpos getpos "another unit" without the ".

I have tried this command : player setpos [getspos this select 1, getpos this select 1, (getpos this select 2) ] but the unit spawn very far away.

Is there a command to make a unit spawn withing a few meters from another one ? Like x=1m y=1m z=0 ?

Thanks

jr

Share this post


Link to post
Share on other sites

When you use the getpos setpos method, you need to include an X, Y offset (-3, +3, whatever distance in meters); or use BIS_fnc_findSafePos. Or you can pass the position plus an array of specific units to spawn using BIS_fnc_spawnGroup.

Share this post


Link to post
Share on other sites

I tried the BIS_fnc_findSafePos, and it dosen't work. I understand I need to include an offset but I don't know the syntax, the one I tried (player setpos [getspos this select 1, getpos this select 1, (getpos this select 2) ]) don't work, how do I include an offset to the setpos function ?

Edited by jackrabbitslim7

Share this post


Link to post
Share on other sites
player setpos [getspos this select 1, getpos this select 1, (getpos this select 2) ]

Is it a typo here, or shouldn't the first one say 0, not 1 in there? Also in the first case it says getspos. An offset would be added by just doing -

player setpos [(getpos this select 0) + 10, (getpos this select 1) + 10, getpos this select 2]

For random placement around the point, you could use (just as an example, for practical uses, defining the global minRadius/maxRadius over at every init probably isn't the optimal solution) -

minRadius = 5;
maxRadius = 15;
player setpos [
    (getpos this select 0) + ((minRadius + (maxRadius - minRadius))*(1 - random 2)),
    (getpos this select 1) + ((minRadius + (maxRadius - minRadius))*(1 - random 2))
];

Is this for multiplayer or singleplayer and do you intend to spawn the groups mid-game or is an editor solution fine?

As for BIS_fnc_findSafePos not working, you probably know this but just in case - you would need to include the Functions module first and then after waituntil {!isnil "bis_fnc_init"}; you can call the BIS functions like this - [[500,500,0],5,30,1,0,10,0] call BIS_fnc_findSafePos;.

Here's an editor solution -

Have one group leader's placement radius what you want it to be (or if you want to use several "random circle" areas, you can add markers and group the leader to those (you can do that, even though in group mode the markers are invisible), he'll be automatically spawned relative to a random one (along with his group), with the placement radius still in effect). Give the first group leader a name (for this example, I'm presuming leader1). Put this in the other group leader's (or any member's, but only to a single one) init -

0 = [5,25,units group this,leader1] spawn {
      _minRadius = _this select 0;
      _maxRadius = _this select 1;
      _targetPos = getPos (_this select 2);
      {
             _x setpos [
                    (_targetPos select 0) + ((_minRadius + (_maxRadius - _minRadius))*(1 - random 2)),
                    (_targetPos select 1) + ((_minRadius + (_maxRadius - _minRadius))*(1 - random 2))
             ];
      }forEach (_this select 2);
};

Or you could predefine the latter part in init.sqf by using the same exact code as above, just replace the first line with these two lines

moveUnitsToObject = {
    private["_minRadius","_maxRadius","_targetPos"];
...

If using this, then in the second group leader's init (and any other group leader's init, if you want to move more groups) you would use -

[5,25,units group this,leader1] call moveUnitsToObject;

This will however make the troops move to their formation positions as they're all spawned randomly and are set to stick to formation by default (can be disabled in editor for each unit by setting the "Special" property to "None"). Alternatively you could define a custom function to place them correctly. I've displayed such a function in this post (as applyWedge that takes a group for argument); you'd just define that in init.sqf and call after moveUnitsToObject like this -

group call applyWedge;

Edited by geqqo
Renamed moveGroupToObject into moveUnitsToObject since that's what it literally does; no more nil = ...

Share this post


Link to post
Share on other sites

Hi,

Thank you a lot, that's exactly what I was looking for. It was more than a typo, I just wasn't understanding what I was using, so I changed the numbers thinking it would increase the distance, but now it work for me with a slightly different form than the one proposed, I nammed the reference leader "me" and the object "tank" and I used this form : "tank setpos [(getpos me select 0) + 10, (getpos me select 1) + 10, getpos me select 2]" so now it spawn the tank near me every time at random position, without the tank being in my team. I tried to do the same with a team and it worked, the only hassle was to modify every single unit in the group in order for them to spawn all near me but it's perfectly fine.

I still don't get what the select and the following number mean, I thought +10,+10,0 would be enough to establish the position but no.

I intend to play those missions mainly solo with mods, but I could host some coop games sometimes. The Idea is to have a good replayability, the enemies spawn anywhere on the map (but together thanks to you) and the friendly too, using the commander module the player have to get rid of the enemy forces using combined arms and support.

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  

×