Ivanoff.N 61 Posted March 22, 2017 Hi. I have a script that handles a group of 3 units. One of the group is a leader , another is just a rifleman and the third one is a gunner of a static weapon. In a script I can select the leader by the following code: _leader = leader _group //(_group is not defined here but lets pretend it is) I can select the rest of the units with: _restofunits = (units _group - [_leader]); This way I have 2 units left, but I need to select one of them, what would the code be ? Share this post Link to post Share on other sites
ProfTournesol 956 Posted March 22, 2017 _groupmember = nameofgroup select 1 Share this post Link to post Share on other sites
Ivanoff.N 61 Posted March 22, 2017 On 3/22/2017 at 7:11 PM, ProfTournesol said: _groupmember = nameofgroup select 1 Thanks that works, however has its limitations: _restofunits = (units _group - [_leader]); _groupmember = _restofunits select 1 //(Sometimes he is a rifleman, but sometimes can be static gunner is there any way to check ?) Share this post Link to post Share on other sites
Grumpy Old Man 3549 Posted March 22, 2017 Alternatively: _units = units _group; _units params ["_unit1","_unit2","_unit3"]; Usually when placing units in the editor the first placed unit will always be the leader, then goes the second unit etc. Cheers Share this post Link to post Share on other sites
Ivanoff.N 61 Posted March 22, 2017 On 3/22/2017 at 8:00 PM, Grumpy Old Man said: Alternatively: _units = units _group; _units params ["_unit1","_unit2","_unit3"]; Usually when placing units in the editor the first placed unit will always be the leader, then goes the second unit etc. Cheers Okay so if I need to select a gunner of a static weapon from this group do I go: if (assignedvehicle _unit1 iskindof "Staticweapon") then {_unit1 = _gunner}; if (assignedvehicle _unit2 iskindof "Staticweapon") then {_unit2 = _gunner}; if (assignedvehicle _unit3 iskindof "Staticweapon") then {_unit3 = _gunner}; Is that how I select a gunner ? Share this post Link to post Share on other sites
MKD3 27 Posted March 23, 2017 params ["_unit"]; private ["_selectedUnit"]; _group = group _unit; { _vehicle = vehicle _x; //if vehicle != unit, unit is mounted if ((_unit != _vehicle) && (_unit == gunner _vehicle)) then {_selectedUnit = _x}; } foreach units _group; _selectedUnit; Try that, written here so not tested but should return a unit if it is a gunner. Share this post Link to post Share on other sites
kibaBG 54 Posted February 2, 2023 On 3/22/2017 at 8:00 PM, Grumpy Old Man said: Alternatively: _units = units _group; _units params ["_unit1","_unit2","_unit3"]; Usually when placing units in the editor the first placed unit will always be the leader, then goes the second unit etc. Cheers This gives error "global variable in local space" or something ... Share this post Link to post Share on other sites
Harzach 2518 Posted February 2, 2023 On 2/2/2023 at 6:50 PM, kibaBG said: This gives error "global variable in local space" or something ... Where and how are you trying to execute this? Show your code. 1 Share this post Link to post Share on other sites
kibaBG 54 Posted February 3, 2023 []execVM from initServer.sqf I wanted to spawn a group, select the members one buy one and give command to enter in a bunker, but I completely abandoned the idea ... This is working fine: private _bunker = createVehicle ["Land_BagBunker_Large_F" ,getMarkerPos _rtown,[],0,"NONE"]; private _bnkgrp = createGroup [independent,true]; _allbnkpos = _bunker buildingPos -1; _bnkpos1 = selectRandom _allbnkpos; _allbnkpos = _allbnkpos - [_bnkpos1]; _bnkpos2 = selectRandom _allbnkpos; _allbnkpos = _allbnkpos - [_bnkpos2]; _bnkpos3 = selectRandom _allbnkpos; _allbnkpos = _allbnkpos - [_bnkpos3]; _bnkpos4 = selectRandom _allbnkpos; _allbnkpos = _allbnkpos - [_bnkpos4]; _unit1 = _bnkgrp createUnit ["CUP_I_GUE_Soldier_MG",_bnkpos1, [], 0, "CAN_COLLIDE"]; _unit1 disableAI "PATH"; _unit1 setUnitPos "UP"; _unit2 = _bnkgrp createUnit ["CUP_I_GUE_Soldier_AKM",_bnkpos2, [], 0, "CAN_COLLIDE"]; _unit1 disableAI "PATH"; _unit1 setUnitPos "UP"; _unit3 = _bnkgrp createUnit ["CUP_I_GUE_Soldier_AKSU",_bnkpos3, [], 0, "CAN_COLLIDE"]; _unit1 disableAI "PATH"; _unit1 setUnitPos "UP"; _unit4 = _bnkgrp createUnit ["CUP_I_GUE_Soldier_AT",_bnkpos4, [], 0, "CAN_COLLIDE"]; _unit1 disableAI "PATH"; _unit1 setUnitPos "UP"; Actually none of the methods work for selecting a units in a group so far ... Share this post Link to post Share on other sites
Harzach 2518 Posted February 4, 2023 On 2/3/2023 at 11:28 PM, kibaBG said: Actually none of the methods work for selecting a units in a group so far ... What methods? What have you tried? Give us the full picture, otherwise we're just pulling teeth. 1 Share this post Link to post Share on other sites
kibaBG 54 Posted February 6, 2023 On 2/4/2023 at 2:16 AM, Harzach said: What methods? What have you tried? Give us the full picture, otherwise we're just pulling teeth. I just spawn them in the bunker, but most of them do not spawn there. Share this post Link to post Share on other sites
jakeplissken 81 Posted February 6, 2023 I used this in a script. This selects the group leader and performs scripting actions on him. _offguy = [_housepos, EAST, ["I_officer_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup; ((units _offguy) select 0) setVehicleVarName "commandant"; commandant = ((units _offguy) select 0); ((units _offguy) select 0) disableAI 'PATH'; ((units _offguy) select 0) setUnitPos "AUTO"; ((units _offguy select 0) selects the group leader. 1 Share this post Link to post Share on other sites