bbaanngg 0 Posted August 2, 2019 In a project I have been working on I use this code to spawn empty groups based on how many markers are in a trigger. { missionNamespace setVariable [format["grp%1",_x], createGroup east]; } forEach _Markers; So how would I go about spawning 1 opfor unit in each group until all groups have 1 unit in them? Or is there a better way of doing this in general? Share this post Link to post Share on other sites
Smart Games 76 Posted August 3, 2019 { _group = creategroup “east“; "B_RangeMaster_F" createUnit [getMarkerPos _x, _group]; } foreach _Markers; Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted August 3, 2019 27 minutes ago, Smart Games said: { _group = creategroup “east“; "B_RangeMaster_F" createUnit [getMarkerPos _x, _group]; } foreach _Markers; You're absolutely sure this works? Cheers Share this post Link to post Share on other sites
Smart Games 76 Posted August 3, 2019 not any longer 🙂 1 Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted August 3, 2019 32 minutes ago, Smart Games said: not any longer 🙂 Check the second line, heh. Cheers 1 Share this post Link to post Share on other sites
mrcurry 498 Posted August 3, 2019 (edited) 8 hours ago, bbaanngg said: In a project I have been working on I use this code to spawn empty groups based on how many markers are in a trigger. { missionNamespace setVariable [format["grp%1",_x], createGroup east]; } forEach _Markers; So how would I go about spawning 1 opfor unit in each group until all groups have 1 unit in them? Or is there a better way of doing this in general? While it's a little unclear what exactly you want here's my contribution. Nvm I got it. Separating the spawn of groups and units can be beneficial if you want to, say, do a caching system. Use the groups as holders for the group data and units are spawned only when players get close. However keep in mind that you can run into the 255 group limit pretty quickly if you do big missions so maybe it's not the best way. If that's what you want you really just access the group you just created using getVariable and the same variable format as when you created the group. The variable name can be gotten from the marker. //Creating groups, note that we also store which marker the group belongs to do a cheap lookup when the time is right. { private _grp = createGroup east; _grp setVariable ["marker", _x]; missionNamespace setVariable [format["grp%1",_x], createGroup east]; } forEach _Markers; //Creating units (can be done at any point later) private _grp = missionNamespace getVariable [format ["grp%1", _x], grpNull]; if(!isNull _grp) then { private _u = _grp createUnit ["Class", markerPos (_grp getVariable "marker"), [], 25, "NONE"]; }; Note: If you have no need to delay the spawn of the units until later then it's just wasted CPU cycles to do the above. If so just go with w/e floats your boat from below. A. To put one unit at each marker just do what's been suggested: private _unitClasses = ["class1", "class2", "classN"]; { private _u = createGroup OPFOR createUnit [selectRandom _unitClasses, markerPos _x, [], 25, "NONE"]; } forEach _Markers; B. Distribute a given number of units across the markers randomly: private _unitClasses = ["class1", "class2", "classN"]; //Change to use the classes you want to use. private _numUnits = 66; //This can changed to read from params or be random or w/e. private _markerTemp = +_Markers; //Make a copy of _Markers private "_x"; for "_i" from 1 to _numUnits do { //Delete a marker from the temp list at random. _x = _markerTemp deleteAt floor random count _markerTemp; //Create the unit private _u = createGroup OPFOR createUnit [selectRandom _unitClasses, markerPos _x, [], 25, "NONE"]; //Out of markers? if(count _markerTemp == 0) then { //Yes, make another copy _markerTemp = +_Markers; }; }; Edited August 3, 2019 by mrcurry Misunderstood OP 2 1 Share this post Link to post Share on other sites
Smart Games 76 Posted August 3, 2019 Edit: { _group = creategroup east; "B_RangeMaster_F" createUnit [getMarkerPos _x, _group]; } foreach _Markers; Maybe I'm stupid, but i did it like this all the time... Who knows.. 2 Share this post Link to post Share on other sites
bbaanngg 0 Posted August 6, 2019 On 8/3/2019 at 3:53 AM, mrcurry said: While it's a little unclear what exactly you want here's my contribution. Nvm I got it. Separating the spawn of groups and units can be beneficial if you want to, say, do a caching system. Use the groups as holders for the group data and units are spawned only when players get close. However keep in mind that you can run into the 255 group limit pretty quickly if you do big missions so maybe it's not the best way. If that's what you want you really just access the group you just created using getVariable and the same variable format as when you created the group. The variable name can be gotten from the marker. //Creating groups, note that we also store which marker the group belongs to do a cheap lookup when the time is right. { private _grp = createGroup east; _grp setVariable ["marker", _x]; missionNamespace setVariable [format["grp%1",_x], createGroup east]; } forEach _Markers; //Creating units (can be done at any point later) private _grp = missionNamespace getVariable [format ["grp%1", _x], grpNull]; if(!isNull _grp) then { private _u = _grp createUnit ["Class", markerPos (_grp getVariable "marker"), [], 25, "NONE"]; }; Note: If you have no need to delay the spawn of the units until later then it's just wasted CPU cycles to do the above. If so just go with w/e floats your boat from below. A. To put one unit at each marker just do what's been suggested: private _unitClasses = ["class1", "class2", "classN"]; { private _u = createGroup OPFOR createUnit [selectRandom _unitClasses, markerPos _x, [], 25, "NONE"]; } forEach _Markers; B. Distribute a given number of units across the markers randomly: private _unitClasses = ["class1", "class2", "classN"]; //Change to use the classes you want to use. private _numUnits = 66; //This can changed to read from params or be random or w/e. private _markerTemp = +_Markers; //Make a copy of _Markers private "_x"; for "_i" from 1 to _numUnits do { //Delete a marker from the temp list at random. _x = _markerTemp deleteAt floor random count _markerTemp; //Create the unit private _u = createGroup OPFOR createUnit [selectRandom _unitClasses, markerPos _x, [], 25, "NONE"]; //Out of markers? if(count _markerTemp == 0) then { //Yes, make another copy _markerTemp = +_Markers; }; }; 11 Thanks for the help. I actually didn't know you could create the group and the unit in the same line like that. I ended up using this: private _unitClasses = ["class1", "class2", "classN"]; { private _u = createGroup OPFOR createUnit [selectRandom _unitClasses, markerPos _x, [], 25, "NONE"]; } forEach _Markers; It works perfectly, thanks again! Share this post Link to post Share on other sites