Jump to content
Sign in to follow this  
Guck

Place an Ammocrate in random building within set area?

Recommended Posts

Hi all. Have been searching allot but not found a good way to do this.

I want to set an area around a village or something, and then have an ammocrate spawn randomly within any of the buildings in that are.

Is this possible to do?

what im doing now is setting an ammocrate and a bunch of different markers in different buildings and leting it spawn randomly. but its hard to place every marker in a way so that the crate actually survives the spawn it seems..

Thanks for any help!

Cheers

Share this post


Link to post
Share on other sites

I think markers isn’t the most accurate method. You’ll need to get into the building on foot and then save your coordinates.

Paste this in a separate file and call it, for example, pos.sqf:

copyToClipboard str getPos _this

Then when you need to get your position, call it with:

player call compile loadFile "pos.sqf";

Coordinates will be copied to your clipboard. When you have enough coordinates, you can use following code:

if (!isServer) exitWith {};

coords =
[
   [coordinates 1],
   [coordinates 2],
   [coordinates 3]
];

"Box_NATO_Wps_F" createVehicle (coords select ([0,(count coords)-1] call BIS_fnc_randomInt));

Edited by RegEdit

Share this post


Link to post
Share on other sites

Thanks. what if i would use a modified version of this? This does what i want, but it spawns one crate in every building..

_houseList = getMarkerPos "Cache1_marker" nearObjects ["House",25];

{

_c = 0;

while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};

if (_c > 0) then

{

_ranNum = floor(random _c);

_crate = "Box_East_Wps_F" createVehicle [0,0,0];

_crate setPos (_x buildingPos _ranNum);

};

sleep 0.123;

} forEach _houseList;

Is there some way to replace forEach with something that selects one ranom nr from the houseList? and places it there?

Share this post


Link to post
Share on other sites
Is there some way to replace forEach with something that selects one ranom nr from the houseList? and places it there?

Yes, I think so. Try this:

_houseList = getMarkerPos "Cache1_marker" nearObjects ["House",25];
_c = 0;
while {format ["%1", _x buildingPos _c] != "[0,0,0]"} do
{
   _c = _c + 1;
};
if (_c > 0) then
{
   _ranNum = floor (random _c);
   _crate = "Box_East_Wps_F" createVehicle [0,0,0];
   _crate setPos ((_houseList select ([0,(count _houseList)-1] call BIS_fnc_randomInt)) buildingPos _ranNum);
};

Share this post


Link to post
Share on other sites

no luck.. underfined variable in expression: _x and editor craches:P

Share this post


Link to post
Share on other sites

Replace all your code with mine, not only forEach, and this should work.

Share this post


Link to post
Share on other sites

yeah, unfortunately thats what i did=/

Share this post


Link to post
Share on other sites

Your editor shouldn't be crashing due to code like that. Maybe check Steam file integrity?

Share this post


Link to post
Share on other sites
_nearesthouses = getMarkerPos "Cache1_marker" nearObjects ["House",25];
_houseList = [];
{
for "_i" from 0 to 20 do {
	if ( [(_x buildingPos _i), [0,0,0]] call BIS_fnc_arrayCompare ) exitWith {
		if (_i > 0) then {
			_houseList set [count _houseList, [_x, _i]];
		};
	};
};	
}forEach _nearesthouses;

_randomHouse = _houseList select (floor (random (count _houseList)));
_housePos = (_randomHouse select 0) buildingPos (floor (random (_randomHouse select 1)));

_crate = createVehicle ["Box_East_Wps_F", _housepos, [], 0, "CAN_COLLIDE"];

Tested seems to be working fine. Only counts upto 20 house positions.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks alot guys.. we finally made it work. what gave me the error before was that there actually wasnt any "house" able to spawn the create within the radious.

So that gives me a new question. Is there a way to find nearObjects buildings that have the posibility to spawn something? If i just use radious it will select trees, rocks and what not that cant spawn the crate..

some way to filter the array or something..

Share this post


Link to post
Share on other sites

Larrow's code there does just that. Checks nearby houses only, then finds spots within each.

Share this post


Link to post
Share on other sites

Ah shit! overlooked that.. tried it and it all works perfect now:D THANKS!

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  

×