Guck 10 Posted September 7, 2013 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
RegEdit 10 Posted September 7, 2013 (edited) 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 September 7, 2013 by RegEdit Share this post Link to post Share on other sites
Guck 10 Posted September 7, 2013 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
RegEdit 10 Posted September 7, 2013 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
Guck 10 Posted September 7, 2013 no luck.. underfined variable in expression: _x and editor craches:P Share this post Link to post Share on other sites
RegEdit 10 Posted September 7, 2013 Replace all your code with mine, not only forEach, and this should work. Share this post Link to post Share on other sites
Guck 10 Posted September 7, 2013 yeah, unfortunately thats what i did=/ Share this post Link to post Share on other sites
kylania 568 Posted September 7, 2013 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
Larrow 2822 Posted September 7, 2013 _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. 1 Share this post Link to post Share on other sites
Guck 10 Posted September 8, 2013 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
kylania 568 Posted September 8, 2013 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
Guck 10 Posted September 8, 2013 Ah shit! overlooked that.. tried it and it all works perfect now:D THANKS! Share this post Link to post Share on other sites