Jump to content
Sign in to follow this  
frosties

Random positions inside a house?

Recommended Posts

Hello,

Im trying to put a "ambassador" in a mission that the BLUEFOR has to locate and rescue.

I have the AI ambassador spawn in random locations, 8-10 inside a town, and its all working OK.

But when he spawns at a building he always spawns on the roof or standing outside ... and never inside.

Have tried fooling around with different ideas ive found here, but none is working.

anyone have any suggestions?

Share this post


Link to post
Share on other sites

Iterate randomly through the building positions until you find one that's z-value (height) is not over a specific value, probably something around 2, from the ground/sea level.

Share this post


Link to post
Share on other sites

That would probably work if its only one location, but the Ai in this case spawns on around 6 different locations, and i would like him to spawn inside each spawn location instead of outside or on the roof where he is likely to get shot...

Share this post


Link to post
Share on other sites

That's why you first randomly pick the location, then get building positions around that position.

Share this post


Link to post
Share on other sites

i´ve tried this:

this setPos ((nearestBuilding this) buildingPos (random 5));

And it did randomly put the around a building, but as much as it put him inside it also put him on 3-4 positions on the roof and outside the house.

Do i have to go with that, or can i limit the availible positions to just for example: 4-8 wich are inside?

Edited by Frosties

Share this post


Link to post
Share on other sites

10min effort, feel free to refine. Example mission

// nul = [objectToMove,[locationToSearchForBuildingPositions1,loc2,loc3,...],maximumDistanceToSearch,[minHeight,maxHeight]] execvm "rndbldpos.sqf";
// nul = [dude,[pos1,pos2,pos3],20,[1,4]] execvm "rndbldpos.sqf";

if !isserver exitwith {};
private ["_unit","_locations","_range","_height","_location","_bpos","_i","_p"];

_unit = _this select 0;
_locations = _this select 1;
_range = _this select 2;
_height = _this select 3;

// select location
_location = _locations select (floor random count _locations);

// building positions
_bpos = [];
{
 for [{_i = 0;_p = _x buildingpos _i},{str _p != "[0,0,0]"},{_i = _i + 1;_p = _x buildingpos _i}] do {
   _bpos set [count _bpos,_p];
 };
} foreach (nearestObjects [_location, ["Building"], _range]);

// height
private ["_tmp","_min","_max","_h"];
_tmp = [];
_min = _height select 0;
_max = _height select 1;
{
 _h = _x select 2;
 if (_h >= _min && _h <= _max) then { _tmp set [count _tmp,_x] };
} foreach _bpos;

if (count _tmp > 0) then {
 _unit setpos (_tmp select (floor random count _tmp));
} else {
 player globalchat "Unable to move unit, no suitable building positions found.";
};

Share this post


Link to post
Share on other sites

The random part looks great!

However, is t it posible to add different building positions to each pos1, pos2 for example? In some houses a number thats inside in one, can be on the roof on another i guess. And the whole idea of him being inside is so that the enemy is less prone to find him, and not make it too easy for the rescue squad.

Very nice of you to take your time and helping me :)

Share this post


Link to post
Share on other sites

Well, that was a dynamic approach so editor doesn't need to do any manual position finding.

If you can bother, you could find all the available positions and record them. That way you can make sure that hes always inside. Plus, you can select any position, not just predefined building positions.

1. Make a repeatedly radio trigger with this in onact:

if (isnil "xxxpos") then {xxxpos = []}; xxxpos set [count xxxpos, getposasl player]; copyToClipboard str xxxpos

2. Go run around in editor, when you are in a suitable position hit the radio trigger.

3. Go to next position, radio again.

4. Repeat 3. as many times as you want.

5. Open Notepad, hit paste.

6. You will get something like this:

[[8205.37,9115.56,71.3897],[8196.58,9144.61,71.4865],[8206.97,9168.26,71.3897]]

7. To move the unit from init field, trigger or init.sqf do:

nul = [unitName,[[8205.37,9115.56,71.3897],[8196.58,9144.61,71.4865],[8206.97,9168.26,71.3897]]] execvm "rndsetpos.sqf"

rndsetpos.sqf:

if isserver then {
 private "_p";
 _p = _this select 1;
 (_this select 0) setposasl (_p select (floor random count _p));
};

Edited by Shuko

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  

×