Robustcolor 30 Posted September 11, 2020 Could somebody help on how to spawn something near these bushes using NearestTerrainObjects and not spawning twice on same pos. _allBushes = nearestTerrainObjects [player, [Bush], 250, false]; for "_i" from 1 to 5 do _pos = selectRandom _allBushes _grp = createGroup east; _unit = _grp createUnit ["C_man_p_beggar_F", [0,0,0], [], 0, "FORM"]; _unit setPos _pos; }; Share this post Link to post Share on other sites
gc8 977 Posted September 11, 2020 There you go _allBushes = nearestTerrainObjects [player, [Bush], 250, false]; for "_i" from 1 to 5 do { if(count _allBushes == 0) exitWith {}; // Get random bush and delete it from list _index = floor random (count _allBushes); _pos = getpos (_allBushes # _index); _allBushes deleteAt _index; _grp = createGroup east; _unit = _grp createUnit ["C_man_p_beggar_F", [0,0,0], [], 0, "FORM"]; _unit setPos _pos; }; 3 Share this post Link to post Share on other sites
Robustcolor 30 Posted September 12, 2020 Thanks @gc8 Share this post Link to post Share on other sites
Robustcolor 30 Posted October 7, 2020 On 9/11/2020 at 10:53 AM, gc8 said: _allBushes = nearestTerrainObjects [player, [Bush], 250, false]; Is it possible to add a max limit of how many positions it can find? Instead of all bushes in a 250m radius i would like it to be something like 15 bushes in a 250m radius. Share this post Link to post Share on other sites
gc8 977 Posted October 7, 2020 1 hour ago, Robustcolor said: Is it possible to add a max limit of how many positions it can find? Instead of all bushes in a 250m radius i would like it to be something like 15 bushes in a 250m radius. you can try: _someBushes = _allBushes select [0,15]; but I don't know if the bushes will be evenly distributed. For that you may need random selection Share this post Link to post Share on other sites
phronk 898 Posted October 7, 2020 Make sure Bush is in quotes: _allBushes = nearestTerrainObjects [player, ["Bush"], 250, false]; 2 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 17, 2020 @gc8 Is there a simple way of sorting out all the bushes that is near a tree, say 5 meter since it can cause stuck issues? Share this post Link to post Share on other sites
pierremgi 4829 Posted December 17, 2020 49 minutes ago, Robustcolor said: @gc8 Is there a simple way of sorting out all the bushes that is near a tree, say 5 meter since it can cause stuck issues? Sure! If I can... On server (only), {_x hideObjectGlobal TRUE} forEach (nearestTerrainObjects [ theCenterOfYourPlace, ["Bush"], 5, false]); If "bush" doesn't work, try with "tree" or even "hide" If no joy, forget nearestTerrainObjects and try to cursorObject it in preview, writing in one of the watch lines : getModelInfo cursorObject (for p3d model) then: {_x hideObjectGlobal TRUE} forEach ((nearestObjects [ theCenterOfYourPlace, [], 5, true]) select {getModelInfo _x #0 == theP3dYouReadInConsole} ); 2 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 18, 2020 @pierremgi That worked pretty good, had to remove the parentheses. _nearObjects = nearestObjects [_pos, [], 15, true] select {getModelinfo _x #0 == "t_inocarpus_f.p3d"}; Since i'm using the code from above, i want the loop to skip create an unit if that particular object is near the position, is this a good way to do it? I'm using a isNil check to stop the loop and continue with next loop. _allBushes = nearestTerrainObjects [player, [Bush], 250, false]; for "_i" from 1 to 5 do { if(count _allBushes == 0) exitWith {}; _index = floor random (count _allBushes); _pos = getpos (_allBushes # _index); _allBushes deleteAt _index; _nearObjects = nearestObjects [_pos, [], 15, true] select {getModelinfo _x #0 == "t_inocarpus_f.p3d"}; if (!isNil "_nearObjects") then { _grp = createGroup east; _unit = _grp createUnit ["C_man_p_beggar_F", [0,0,0], [], 0, "FORM"]; _unit setPos _pos; };}; Share this post Link to post Share on other sites
pierremgi 4829 Posted December 18, 2020 removing the global parenthesis, just invalidate the selection (select is forgotten). So, your nearestObjects will return all objects (footprints, craters, agents,..) You must focus on the selection and make getModelInfo _x #0 match with your unwanted p3d !isNil "_nearObjects" is always true: you just defined it in the line above. check: !(_nearestObjects isEqualTo []) If you want to skip these returned objects, check for the contrary: if (_nearestObjects isEqualTo []) then { create... 2 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 18, 2020 Thanks @pierremgi _nearestObjects = ((nearestObjects [_pos, [], 15, true]) select {getModelInfo _x #0 == "t_inocarpus_f.p3d"}); if (_nearestObjects isEqualTo []) then { Share this post Link to post Share on other sites
Robustcolor 30 Posted December 21, 2020 On 10/7/2020 at 11:06 AM, gc8 said: _someBushes = _allBushes select [0,15]; but I don't know if the bushes will be evenly distributed. For that you may need random selection How can I do a random selection within a select [] command, the regular select [0,15]; does not random pick locations. Share this post Link to post Share on other sites
gc8 977 Posted December 21, 2020 1 minute ago, Robustcolor said: How can I do a random selection within a select [] command? I think you want this: _someBushes = _allBushes select [0,15]; _bush = selectRandom _someBushes; Share this post Link to post Share on other sites
Robustcolor 30 Posted August 12, 2023 On 9/11/2020 at 10:53 AM, gc8 said: floor random (count _allBushes); Just a quick question here, is there any different in using floor vs round here? Also, what's the difference in using this above vs this below with -1? What does the -1 do with count. (round (random (count _allBushes -1))); Share this post Link to post Share on other sites
phronk 898 Posted August 12, 2023 Round simply rounds the number up, whereas floor does the opposite. 1 Share this post Link to post Share on other sites
Robustcolor 30 Posted August 12, 2023 Thanks @phronk. What's does the -1 do when using it in this context? Share this post Link to post Share on other sites
mrcurry 496 Posted August 12, 2023 8 hours ago, phronk said: Round simply rounds the number up, whereas floor does the opposite. A slight but important correction: round does not round up, it rounds to nearest whole integer. Using round X where 0 <= decimal (X) < 0.5 will cause it to behave like floor. ceil always rounds up. 9 hours ago, Robustcolor said: Just a quick question here, is there any different in using floor vs round here? Yes, you no longer have uniform chances for each possible value and the possible max value increases by 1 floor random 10 has a possible and uniform range of 0-9 (10 possible integers). All with equal chance of getting picked. round random 10 has a possible range 0-10 (11 possible outcomes) and the extreme values 0 and 10 are less likely to occur. My gut says about half as likely as all other outcomes but I may be wrong, probability is hard. 9 hours ago, Robustcolor said: Also, what's the difference in using this above vs this below with -1? What does the -1 do with count. (round (random (count _allBushes -1))); It's essentially the same as using floor and no -1 but with a non-uniform distribution, as I explained above. Basically if your working with indicies for arrays and you want an even spread always use floor. If you do want an uneven spread and proper control either use the alternative syntax: random [min, mid, max] or work with weighted randoms instead. See selectRandomWeighted for more info on that. 1 Share this post Link to post Share on other sites