Jump to content

Recommended Posts

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
25 minutes ago, 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

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
32 minutes ago, 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
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
On 3/22/2017 at 10: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
3 hours ago, kibaBG said:

 

This gives error "global variable in local space" or something ...

 

Where and how are you trying to execute this? Show your code.

  • Like 1

Share this post


Link to post
Share on other sites

[]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
2 hours ago, 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.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/4/2023 at 4: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

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.

  • Like 1

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

×