Jump to content
pcc

Filling all vehicle turrets in warfare

Recommended Posts

Default warfare only spawns 1 AI gunner for all vehicles regardless of number turrets. 

I tried adding while loop, but still only get 1 AI gunner.

if (_vehicle EmptyPositions "gunner" > 0) then
	{
		g = 0;
		while { g <= (_vehicle EmptyPositions "gunner") } do
		{
		_gunner = _team CreateUnit [_soldierName,_factoryPosition,[],0.2,"FORM"];
		[_gunner] AllowGetIn true;
		[_gunner] Join _team;
		_gunner MoveInGunner _vehicle;
		[_gunner,_side] Call BIS_WF_InitUnit;
		g = g + 1;
		};
	};

 

Share this post


Link to post
Share on other sites

in arma 2 it is not such easy.

Every vehicle has one gunner only. all other men with a vehicle gun are sitting in a turret.

So you have to use

getInTurret

moveInTurret

The problem is that arma 2 has only a very limited command set for using and detecting vehicle turrets

to detect the turrets of a vehicle I think you need to check the config file of that vehicle But Im not sure.

  • Like 1

Share this post


Link to post
Share on other sites

KK's function is posted here: https://community.bistudio.com/wiki/moveInTurret

 

This is what I've been using in my SOM-Warfare mission, hope it helps:

Spoiler

if (_vehicle EmptyPositions "gunner" > 0) then
{
	// Many thanks to Killzone Kid for posting this very helpful function in the A2 Scripting Commands.
	Private ["_turrets","_turretsArray"];
	_turrets = configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Turrets";
	_turretsArray = [];

	Private ["_i","_j"];
	for "_i" from 0 to (count _turrets - 1) do 
	{
		_turretsArray set [count _turretsArray, [_i]];
		for "_j" from 0 to count (_turrets >> configName (_turrets select _i) >> "Turrets") - 1 do 
		{
			_turretsArray set [count _turretsArray, [_i, _j]];
		};
	};

	_gunner = _team CreateUnit [_soldierName,GetPos _vehicle,[],0.2,"FORM"];
	[_gunner] AllowGetIn true;
	_gunner MoveInGunner _vehicle;
	[_gunner,sideJoined] Call BIS_WF_InitUnit;

	// Fill any remaining empty turrets.
	{
		_turretUnit = _vehicle turretUnit _x;
		if (isNull _turretUnit) then 
		{
			_gunner = _team CreateUnit [_soldierName,_factoryPosition,[],0.2,"FORM"];
			[_gunner] AllowGetIn true;
			_gunner moveInTurret [_vehicle, _x];
			[_gunner,sideJoined] Call BIS_WF_InitUnit;
		};
	} forEach _turretsArray;
};

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

This uses KKs function as well and might fit ur needs:

 

KK_fnc_commonTurrets = {
	private ["_arr","_trts"];
	_arr = [];
	_trts = configFile / "CfgVehicles" / typeOf _this / "Turrets";
	for "_i" from 0 to count _trts - 1 do {
		_arr set [count _arr, [_i]];
		for "_j" from 0 to count (
			_trts / configName (_trts select _i) / "Turrets"
		) - 1 do {
			_arr set [count _arr, [_i, _j]];
		};
	};
	_arr
};

_turret_array = _vehicle call KK_fnc_commonTurrets;
_crew = crew _vehicle;

if(count _crew > 0) then { _team = group (_crew select 0);}
else { _team = createGroup side _vehicle; };

_team addVehicle _vehicle;

{
 if (isNull _vehicle turretUnit _x) then
 {
  _gunner = _team createUnit [_soldierName,_factoryPosition,[],0.2,"FORM"];

 [_gunner] AllowGetIn true;
 _gunner moveInTurret [_vehicle, _x] 
 };
} forEach _turret_array;

 

Edited by sarogahtyp
corrected syntax
  • 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

×