Jump to content
Sign in to follow this  
frosties

Random placing of vehicles

Recommended Posts

Hello,

Im sitting here and trying to get some random placement of vehicles in my missions.

I have a shilka that is grouped to several markers on the map so the placement is working fine.

But when i try to use the same markers for another shilka they sometimes spawn in the same place.

Is there a way to spawn them in a different place if there already is one at one marker?

additionaly:

How can i make it so that the shilka gets some support personell deployed wherever the shilka spawns?

ive tried to group them but that only makes the infantry start running to the location of the shilka...

Appreciate any help, thank you

Share this post


Link to post
Share on other sites

This would be a way to do it using a little script. The Shilkas and Markers must have names.

Here... 3 Shilkas will be placed randomly on 3 of 8 markers. A marker won't be used twice. Groups of 5 will also be spawned at each Shilkas new position.

Call this from somewhere...preferably your init.sqf like this:-

nul = [] execVM "place_shilkas.sqf";

Create a file called "place_shilkas.sqf" in your mission folder. You must have the Functions Module placed on the map.

place_shilkas.sqf:-

//make arrays containing the shilkas and markers
_shilkas = [shilka_01,shilka_02,shilka_03];
_markers = ["mkr_01","mkr_02","mkr_03","mkr_04","mkr_05","mkr_06","mkr_07","mkr_08"];

//loop through the shilkas
for "_i" from 0 to (count _shilkas)-1 do {

//select a random marker
_mkr = _markers select (floor (random (count _markers)));

//move a shilka
(_shilkas select _i) setpos (getMarkerPos _mkr);

//spawn group of 5 at the marker/shilka position
_grp = [getMarkerPos _mkr, EAST, 5] call BIS_fnc_spawnGroup;

//remove the marker from the list so it can't be used again
_markers = _markers - [_mkr];

sleep 0.01;

};

EDIT: Added a demo mission for you.

Edited by twirly
Added demo mission

Share this post


Link to post
Share on other sites

Great! Worked awesome!!

If i would like to build it so that there is something else that spawns with the shilka, say a radar, tents and stuff (a small camp so to speak) would that be something i could use this script for?

EDIT.

Found out how to add more units to the script.

But how can i put in some offset? when i put in vehicles they keeps crashing in to each other when spawned...

	_grp = [getMarkerPos _mkr, WEST, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> "USMC_InfSquad")] call BIS_fnc_spawnGroup;
_grp = [getMarkerPos _mkr, WEST, ["USMC_WarfareBAntiAirRadar"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;

Edited by Frosties

Share this post


Link to post
Share on other sites

Try this mate. This is the way I thought of doing that was fairly easily.

Whatever you have within a 20m radius of your Shilka will be deleted and recreated at the new location along with the Shilka.

You can change the 20 meters easily in the script. Look for the line:-

_list = (_shilkas select _i) nearObjects 20;

..and change the 20.

The only thing is...some stuff does not come across properly. You'll have to experiment to see what works and what does not. Sandbags... for instance end up spread out for some reason. I don't think it's my code... so I dunno what causes that.

It's not perfect because of this and I'm not happy.... but anyway....it's something for you at least.

//make arrays for the shilkas and markers
_shilkas = [shilka_01,shilka_02,shilka_03];
_markers = ["mkr_01","mkr_02","mkr_03","mkr_04","mkr_05","mkr_06","mkr_07","mkr_08"];

_list = [];
_shilkapos = [0,0,0];

//loop through the shilkas
for "_i" from 0 to (count _shilkas)-1 do {

//get list of objects near shilka
_list = (_shilkas select _i) nearObjects 20;

_list = _list  - [_shilkas select _i];

//get shilkas position
_shilkapos = position (_shilkas select _i);

_things = [];
_relpos = [0,0,0];

//save the objects positions relative to the shilka
for "_j" from 0 to (count _list)-1 do {
	_relpos = [(_shilkapos select 0) - ((getpos (_list select _j)) select 0),(_shilkapos select 1) - ((getpos (_list select _j)) select 1),0];
	_things set [count _things,[typeOf (_list select _j),_relpos,direction (_list select _j)]];
	deleteVehicle (_list select _j);
	sleep 0.01;
};

//select the marker
_mkr = _markers select (floor (random (count _markers)));

//move the shilkas
(_shilkas select _i) setpos (getMarkerPos _mkr);

//get shilkas position
_shilkapos = position (_shilkas select _i);

//restore the objects at their new locations
for "_j" from 0 to (count _things)-1 do {
	_thing = _things select _j;
	_typeof = _thing select 0;
	_relpos = _thing select 1;
	_direct = _thing select 2;
	_obj = _typeof createVehicle ([(_shilkapos select 0) - (_relpos select 0),(_shilkapos select 1) - (_relpos select 1),0]);
	_obj setdir _direct;
	sleep 0.01;
};

//spawn group of 5
_grp = [getMarkerPos _mkr, EAST, 5] call BIS_fnc_spawnGroup;

//remove the marker from the list so it can't be used again
_markers = _markers - [_mkr];

sleep 0.01;

};

EDIT: To stop the crashing you need to offset the objects you are spawning relative to the Shilka. There's code in what I posted that shows the math.

Edited by twirly

Share this post


Link to post
Share on other sites

@twirly:

Thank you very much, works like a charm

Really appreciate you taking your time!

Share this post


Link to post
Share on other sites

Follow up question:

Whenever i try o attach a trigger or something to a unit that have been moved it keeps getting turned down.

Do i have to put the INIT line of the vehicle somewhere in the script?

Maybe the INIT line i put in the editor gets overlooked when moving the vehicle to the new location.

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  

×