Jump to content
fish44

Random spawn in selection of locations.

Recommended Posts

Hi all,

Found a video some time back showing how to get an object to spawn in one of several designated locations, but can't find it now :(. (I remember i had to place an object at each of the locations). Can anyone tell me how its done.

Cheers.

Share this post


Link to post
Share on other sites

Place markers in the spawn positions, group the object to the markers.

Share this post


Link to post
Share on other sites

K, got it working.

Wondering now, if it can be used to place a object e.g. person or weapons cache, in one of several buildings, since the marker has no init field, how can i give it a specific position (3 coordinates) ?

Cheers.

Share this post


Link to post
Share on other sites
K, got it working.

Wondering now, if it can be used to place a object e.g. person or weapons cache, in one of several buildings, since the marker has no init field, how can i give it a specific position (3 coordinates) ?

Cheers.

puttin objects in buildings is a little trickier becuase buildings have different numbers of palcement positions from one another.

i have attempted a script that has had moderate success in doing this. the biggest problem i am finding is that weaponholder placement is an invisible box that can injure a player or even kill them when they run past. hopefully you can find some value in this as a starting point.

http://forums.bistudio.com/showthread.php?137958-weaponholder-pushes-weapons-outside-building

Share this post


Link to post
Share on other sites

Thanks for quick replies guys, and video link.

Edit.

Working now (not quite). Used a little tool I found here, to get exact positions (in X,Y,Z format) inside buildings. The Z coordinate seemed a little off, when checked with setPos, so I adjusted. Little tedious to get them into the markers, I pasted them into the position parameter for each marker item, but placement is only on the roofs, and not inside the buildings. Maybe its a limitation of the marker approach?

Also noted that the setUnitPos does not seem to work with grouped markers.

Edited by Fish44

Share this post


Link to post
Share on other sites

For future reference, you could use this for obtaining precise positions in buildings or anywhere else:

copyToClipboard format ["this setPosATL %1; this setDir %2;",getPosATL (vehicle player), getDir (vehicle player)];  

Put that in a radio trigger activation line. Then in game, just go to the position you want and activate the trigger via the radio. Now if you CTRL+V you'll paste the commands for setting a unit's position and direction (it will paste as this setposATL [x,y,z]; this setdir x;). That's if you just want to place a unit there. But if you want to place the unit randomly in one of several buildings, you could use that data in the init or a script like this:

	_posArray = [

	[[color="#FF0000"][4467.0,2363.45,0.1][/color], [color="#0000FF"]300.505[/color]],     //--- three exact positions collected using the radio trigger method. An array containing the [color="#FF0000"]position[/color] and [color="#0000FF"]direction[/color] data.
               [[4470.5,2368.5,0.1], 215.394],  
               [[4440,2397.0,0.1], 35.851]
];

_randPos = _posArray call bis_fnc_selectrandom;  
       _pos = _randPos select 0;                                     
       _dir = _randPos select 1;

guyname setposatl _pos;
guyname setdir _dir;

And if you wanted the units to be in a specific stance depending on the position, you could just add a UnitPos to the array, for example

[[4470.5,2368.5,0.1], 215.394, "up"],

And then you'd do

	_randPos = _posArray call bis_fnc_selectrandom;  
       _pos = _randPos select 0;                                     
       _dir = _randPos select 1;
       _Upos = _randPos select 2;

guyname setposatl _pos;
guyname setdir _dir;
guyname setUnitPos _Upos;

Alternatively, if you still wanted to do the marker thing, you could just place a trigger around each marker position, grouped to the unit, that sets his Z coordinate if he should spawn in that position.

Edited by 2nd Ranger

Share this post


Link to post
Share on other sites

Cheers Ranger.

Learned a lot from that and finally got it singing. My first script (although you had all the work done!!

I put in an extra array item to tell me which position it respawned at, to help me debug. 'Grissles' house position module worked fine for me for the locations. Here's what i ended with.

// RandomPos.sqf  Randomly places a unit based on an array of locations.

_posArray = 	[
	[[4073.62,4209.64,0.5],200,1],
	[[4072.69,4201.84,4],250,2],
	[[4077.49,4207.07,6.0],300,3]
	];

_randPos = _posArray call bis_fnc_selectrandom;  
_pos = _randPos select 0;                                     
_dir = _randPos select 1;
_dbg = _randPos select 2;

//--hint line to be removed 
Hint format [" Position %1 Direction %2 Point %3", _pos, _dir, _dbg];

//-- HVT is the unit the script positions.
HVT setposatl _pos;
HVT setdir _dir;
HVT setUnitPos "Down";



I have it running from the unit's init line

nul=execVM "randomPos.sqf"

Wondering if its possible (easily) to pass in the unit and so remove the 'hardcoded' units name in the script, so it could be called from any unit ?

Share this post


Link to post
Share on other sites

Of course, just call it like this

[unitName] execVM "randompos.sqf";

And in the script

_unit  = _this select 0;

... blah blah all the other stuff ...

_unit setposatl _pos;
_unit setdir _dir;
_unit setUnitPos "Down"; 

You can feed a script any parameter you want by using that method. For example you may want to tell the script what direction and unitPos to set, rather than putting them in the array with the position data.

[Man1,300,"up"] execvm "RandomPos.sqf";

_unit  = _this select 0;
_dir  = _this select 1;
_upos  = _this select 2;

...

_unit setposatl _pos;
_unit setdir _dir;
_unit setUnitPos _upos; 

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

×