Jump to content

Recommended Posts

 this script relieves all playable units, saves them to a variable and sorts by faction (cfgfactionclass >>displayName). my question is about navigating configfiles,  most notably navigating and filtering configs. example say you want to filter out all of the unwanted "man" units like "range master", and "survivor" est. is there a more logical approach to this instead of saying is _unit in [array]? also saving units to variables to be used later. my approach looks weird anybody with the knowhow to guide me in the right direction

 

_cfg = "getnumber( _x >> 'scope' ) isEqualTo 2" configClasses (configFile >> "Cfgvehicles");
for "_i" from 0 to ((count _cfg)-1) do {
	if (isClass ((_cfg select _i) )) then {
		_cfgNam = configName (_cfg select _i);	
		_getside = getnumber (configfile >> "Cfgvehicles" >> _cfgNam>> "side");	
		_getfaction = gettext (configfile >> "Cfgvehicles" >> _cfgNam >> "faction");
		_getfac = gettext (configfile >> "cfgfactionclasses" >> _getfaction>> "displayName");
		_getSolClas = gettext (configfile >> "Cfgvehicles" >> _cfgNam>> "displayName");
		_getvehcat = gettext (configfile >> "Cfgvehicles" >> _cfgNam>> "editorSubcategory");
		hint str _getvehcat;
		if !(_getSolClas in ["Crewman","Officer","Competitor","Pilot","Helicopter Crew","UAV Operator","Survivor","Rifleman (Unarmed)","Assault Diver","Diver Team Leader","Diver Explosive Specialist"]) then {
		switch _getvehcat do {
		case ("EdSubcat_Personnel"): {call compile format["missionNamespace setvariable ['man_%1', (missionNamespace getVariable ['man_%1',[]]) + [_cfgNam]];", toupper _getfac];};
		case ("EdSubcat_Cars"): {call compile format["missionNamespace setvariable ['car_%1', (missionNamespace getVariable ['car_%1',[]]) + [_cfgNam]];", toupper _getfac];};
		case ("EdSubcat_APCs"): {call compile format["missionNamespace setvariable ['apc_%1', (missionNamespace getVariable ['apc_%1',[]]) + [_cfgNam]];", toupper _getfac];};
		case ("EdSubcat_Tanks"): {call compile format["missionNamespace setvariable ['tank_%1', (missionNamespace getVariable ['tank_%1',[]]) + [_cfgNam]];", toupper _getfac];};};
		};
		};};

 missionNamespace getVariable "man_NATO";

Share this post


Link to post
Share on other sites

Well unfortunately the engine has no way to interpret what you think is "unwanted" unless you tell it how to do that... 😛

 

You just got to figure out if your unwanted classes got something in common that no other classes has and use that.

 

P.S. It's easier to just filter the config names against an blacklist after you gathered the classes tbh.

  • Like 1

Share this post


Link to post
Share on other sites

You could merge all unit arrays from CfgGroup for every side and check against that, story and odd units usually aren't used in group templates.

But in the end only a single blacklist will be 100% reliable.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

getting time to completion of 138 ms. i will post here all revisions until i get tired of it  

0.1

Spoiler

TAG_fnc_getVehicleWeapons = {
	params[ "_vehicle" ];
	
	_baseCfg = configFile >> "CfgVehicles" >> _vehicle;
	
	_availableWeapons = [];
	
	if ( isClass( _baseCfg >> "Components" >> "TransportPylonsComponent" >> "Pylons" ) ) then {
		{
			_mag = getText( _x >> "attachment" );
			if (getnumber(configFile >> "CfgMagazines" >> _mag >> "scope") isEqualTo 2) then {
			_availableWeapons append [ getText( configFile >> "CfgMagazines" >> _mag >> "pylonWeapon" ) ];
			};
		}forEach ("true" configClasses( _baseCfg >> "Components" >> "TransportPylonsComponent" >> "Pylons" ));
	};
	/*
	_fnc_turrets = {
		params[ "_cfg" ];
		
		_availableWeapons append getArray( _cfg >> "weapons" );
		
		{
			_x call _fnc_turrets;
		}forEach ( "true" configClasses( _cfg >> "turrets" ));
	};
	
	_baseCfg call _fnc_turrets;*/
	
	_availableWeapons	
};

		{
		_cfgName = configName _x;
		_Faction = gettext (_x >> "faction");
		_SolClas = gettext( _x >> "displayName" );
		_FacClass = gettext (configfile >> "cfgfactionclasses" >> _Faction>> "displayName");
		_vehtran = getnumber (_x >> "transportSoldier");
		_vehcat = gettext (_x >> "editorSubcategory");
		switch (_vehcat) do {
			case ("EdSubcat_Personnel") : {
					if !(_SolClas in ["Officer","Competitor","Pilot","Range Master","Helicopter Crew","Helicopter Pilot","Fighter Pilot","Deck Crew","UAV Operator","Survivor","Rifleman (Unarmed)"]) then {
						_varName = format ["Man_%1", toupper _FacClass];
						if (_SolClas == "crewman") then {_varName = format ["Crew_%1", toupper _FacClass];};
						_array = missionNamespace getVariable [_varName,[]];
						_nul = _array pushback _cfgName;
						missionNamespace setVariable [_varName,_array];
					};
			};
			case ("EdSubcat_APCs") : {
					_varName = format ["APC_%1", toupper _FacClass];
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];	
			};
			
			case ("EdSubcat_Cars") : {
				if ((_vehtran) >= 3) then {
					_varName = format ["Car_%1", toupper _FacClass];
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];	
				};
			};
			
			case ("EdSubcat_Artillery") : {
					_varName = format ["arty_%1", toupper _FacClass];
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];	
				};
			
			case ("EdSubcat_Helicopters") : {
					_num = _cfgName call TAG_fnc_getVehicleWeapons;
					if (count (_num) > 1) then {
						_varName = format ["AttackHeli_%1", toupper _FacClass];
						_array = missionNamespace getVariable [_varName,[]];
						_nul = _array pushback _cfgName;
						missionNamespace setVariable [_varName,_array];
					}; 
						if ((_vehtran) > 7) then {
						_varName = format ["TranHeli_%1", toupper _FacClass];
						_array = missionNamespace getVariable [_varName,[]];
						_nul = _array pushback _cfgName;
						hint str _array;
						missionNamespace setVariable [_varName,_array];
					
					};
			};
			
			case ("EdSubcat_Tanks") : {
					_varName = format ["Tank_%1", toupper _FacClass];
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];	
			};
			
			case ("EdSubcat_Planes") : {
					_num = _cfgName call TAG_fnc_getVehicleWeapons;
					if (count (_num) > 2) then {
					_varName = format ["plane_%1", toupper _FacClass];
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];
				};
			
			};

			
			case ("EdSubcat_Boats") : {
					_varName = format ["boat_%1", toupper _FacClass];
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];
			};
			
			case ("EdSubcat_Personnel_SpecialForces") : {
					_varName = format ["Sforce_%1", toupper _FacClass];
					if (_SolClas in ["Assault Diver","Diver Team Leader","Diver Explosive Specialist"]) then {_varName = format ["Diver_%1", toupper _FacClass];};
					_array = missionNamespace getVariable [_varName,[]];
					_nul = _array pushback _cfgName;
					missionNamespace setVariable [_varName,_array];	
			};
		};
		}forEach ( "getNumber( _x >> 'scope' ) isEqualTo 2" configClasses ( configFile >> "CfgVehicles" ));

 

 

Share this post


Link to post
Share on other sites

looking at the cfg files for helicopter show no reference to the weapons they carry, how can i find them? i want to filter transport helicopters and attack helis, but i see no nothing that could help in that way. anyone know where those weapons are stated (cannon,missles,rockets)?

Share this post


Link to post
Share on other sites
On 7/31/2019 at 11:47 PM, sabot10.5mm said:

show no reference to the weapons they carry, how can i find them?

They will be defined under the turret the weapons belong to. There are scripting commands to do this but seeing as we are talking about navigating the config, you will need to loop through all turrets of the vehicle looking at each turrets weapons array.

 

Removed see later post.

 

On 7/31/2019 at 11:47 PM, sabot10.5mm said:

i want to filter transport helicopters

See transportSoldier. Plus you may also want to consider things like HummingBirds benches, which are turrets that have proxyType = "CPCargo".

TAG_fnc_getVehicleTransport = {
	params[ "_vehicle" ];
	
	_baseCfg = configFile >> "CfgVehicles" >> typeOf _vehicle;
	
	_numTransport = 0;
	
	_fnc_turrets = {
		params[ "_cfg" ];
		
		_numTransport = _numTransport + getNumber( _cfg >> "transportSoldier" );
		if ( getText( _cfg >> "proxyType" ) == "CPCargo" ) then {
			_numTransport = _numTransport + 1;
		};
		
		{
			_x call _fnc_turrets;
		}forEach ( "true" configClasses( _cfg >> "turrets" ));
	};
	
	_baseCfg call _fnc_turrets;
	
	_numTransport	
};

( get3DENSelected "object" select 0 ) call TAG_fnc_getVehicleTransport;

 

Both are examples that can be run from the debugConsole in Eden and will return values based on the current selected vehicle.

Elsewhere just replace get3DENSelected with a reference to a vehicle.

 

  • Like 1

Share this post


Link to post
Share on other sites
TAG_fnc_getVehicleWeapons = {
	params[ "_vehicle" ];
	
	_baseCfg = configFile >> "CfgVehicles" >> _vehicle >> "turrets";

	_availableWeapons = [];
	
	_fnc_turrets = {
		params[ "_cfg" ];
		for "_i" from 0 to count _cfg -1 do {
		_cfg1 = _cfg select _i;
		{
			_availableWeapons pushback _x;
		}forEach getArray (_cfg1 >> "weapons");

		};
	};
	
	_baseCfg call _fnc_turrets;
	_availableWeapons;	
};
		

some reason it was only returning flares.. this works for me.

Share this post


Link to post
Share on other sites
8 hours ago, sabot10.5mm said:

some reason it was only returning flares

What vehicle? I tested a whole bunch before posting without problems.

 

8 hours ago, sabot10.5mm said:

this works for me

You do not recurse turrets. Any vehicle that has a turret with any child turrets will not be processed via your code.

Share this post


Link to post
Share on other sites
3 hours ago, Larrow said:

What vehicle? I tested a whole bunch before posting without problems.

 

You do not recurse turrets. Any vehicle that has a turret with any child turrets will not be processed via your code.

test the nato helicopters. nato ah99  "turrets" is empty, weapons is in "mainturret"

as for the recurse turrets part. what if i test isclass(_cfg1 >> "turrets") and call _fnc_turrets again?

Share this post


Link to post
Share on other sites

Planes, helicopters etc. generally don't use the weapons[] array any more for missiles and bombs - only for the gun turrets, laser designators and countermeasures.

Apart from a couple of exceptions, missiles and bombs have been handled by the Dynamic Loadouts system since the Jets DLC was released. This is configured for each vehicle under class Components>>class TransportPylonsComponent>>class pylons where each pylon has an attachment = parameter that defines the default magazine class loaded on to that pylon.

But it's easier to use the getPylonMagazines command on the aircraft rather than dicking around in the configs.

The weapon/launcher for that magazine is assigned by the pylonWeapon parameter in the magazine classname.

To change the munitions assigned to the vehicle's pylons, you use the setPylonLoadout command and use a magazine name - it will automatically add the assigned pylonWeapon to the vehicle when the magazine is added to the pylon this way so you don't need to do separate addWeapon+addMagazine commands for these.

 

So I guess if getPylonMagazines returns nothing for a vehicle, it is probably not armed with anything more than a few gun turrets.

Share this post


Link to post
Share on other sites
18 minutes ago, da12thMonkey said:

But it's easier to use the getPylonMagazines command on the aircraft rather than dicking around in the configs.

Downside is you'd need to spawn the vehicle for this command to work.

Doable but not really necessary if you can retrieve this from config.

 

Maybe spawning using preInit/postInit will work in this case.

Can't really recommend it though.

 

Cheers

Share this post


Link to post
Share on other sites
22 minutes ago, da12thMonkey said:

Planes, helicopters etc. generally don't use the weapons[] array any more for missiles and bombs - only for the gun turrets, laser designators and countermeasures.

Apart from a couple of exceptions, missiles and bombs have been handled by the Dynamic Loadouts system since the Jets DLC was released. This is configured for each vehicle under class Components>>class TransportPylonsComponent>>class pylons where each pylon has an attachment = parameter that defines the default magazine class loaded on to that pylon.

But it's easier to use the getPylonMagazines command on the aircraft rather than dicking around in the configs.

The weapon/launcher for that magazine is assigned by the pylonWeapon parameter in the magazine classname.

To change the munitions assigned to the vehicle's pylons, you use the setPylonLoadout command and use a magazine name - it will automatically add the assigned pylonWeapon to the vehicle when the magazine is added to the pylon this way so you don't need to do separate addWeapon+addMagazine commands for these.

 

So I guess if getPylonMagazines returns nothing for a vehicle, it is probably not armed with anything more than a few gun turrets.

ah99 has weapons listed in the non dynamicloadout baseclass

Share this post


Link to post
Share on other sites
7 minutes ago, Grumpy Old Man said:

Downside is you'd need to spawn the vehicle for this command to work.

Doable but not really necessary if you can retrieve this from config.

 

Maybe spawning using preInit/postInit will work in this case.

Can't really recommend it though. 

 

Cheers

True! I suppose checking if any subclasses in class Components>>class TransportPylonsComponent>>class pylons even exist for that vehicle (or class TransportPylonsComponent alone exists for that vehicle) would do the job.

Obviously there are no pylonMagazines for vehicle that have no pylons configured anyway😄

 

2 minutes ago, sabot10.5mm said:

ah99 has weapons listed in the non dynamicloadout baseclass 

The non-dynamic loadouts version of vehicles, are all-but obsolete. They're mostly just there for backwards compatibility with older missions from before the Jets DLC - there are a couple of other redundant vehicle classes in the game too. BI doesn't recommend using them as assets in current missions. The ones that are accessible through the editor and Zeus, generally will have empty weapons arrays save for the guns and CM

Share this post


Link to post
Share on other sites
58 minutes ago, da12thMonkey said:

Planes, helicopters etc. generally don't use the weapons[] array any more for missiles and bombs - only for the gun turrets, laser designators and countermeasures.

Ah ok.

 

Something like...

TAG_fnc_getVehicleWeapons = {
	params[ "_vehicle" ];
	
	_baseCfg = configFile >> "CfgVehicles" >> typeOf _vehicle;
	
	_availableWeapons = [];
	
	if ( isClass( _baseCfg >> "Components" >> "TransportPylonsComponent" >> "Pylons" ) ) then {
		{
			_mag = getText( _x >> "attachment" );
			_availableWeapons append [ getText( configFile >> "CfgMagazines" >> _mag >> "pylonWeapon" ) ];
		}forEach ( "true" configClasses( _baseCfg >> "Components" >> "TransportPylonsComponent" >> "Pylons" ));
	};
	
	_fnc_turrets = {
		params[ "_cfg" ];
		
		_availableWeapons append getArray( _cfg >> "weapons" );
		
		{
			_x call _fnc_turrets;
		}forEach ( "true" configClasses( _cfg >> "turrets" ));
	};
	
	_baseCfg call _fnc_turrets;
	
	_availableWeapons	
};

( get3DENSelected "object" select 0 ) call TAG_fnc_getVehicleWeapons;

EDIT: Moved pylon check from inside turrets. No need if its all within base cfg.

Share this post


Link to post
Share on other sites

 

 

_cfgVehicle = configfile >> "cfgvehicles" >> "B_MBT_01_cannon_F";

private _turrets = []; 
private _path = []; 
_fnc_getTurretindex = {    
params[ "_cfg" ];    
for "_i" from 0 to count (_cfg >> "Turrets") -1 do  
 {    
 _cfg1 = (_cfg >> "Turrets") select _i;  
  if !(getText( _cfg1 >> "proxyType" ) isEqualTo "CPCargo") then   
  {   
    _path append [_i]; 
 _turrets pushBack ["turret",+_path]; 
 
  };  
 _class = _cfg1 >> "turrets";  
 if (isClass _class) then   
 {  
 _cfg1 call _fnc_getTurretindex;  
 _path deleteAt (count _path - 1); 
 };  
};    
_turrets;  
    
};_cfgVehicle call _fnc_getTurretindex;

made this with the intention to separate turrets, cargo and turretcargo. maybe even include turretcargo into the cargo array

Share this post


Link to post
Share on other sites
Spoiler

TAG_fnc_getVehiclePosition = {
private ["_vehicle","_roles","_cfgVehicle"];

_vehicle = _this param [0,objnull,[objnull,""]];
_roles = [];

if (typename _vehicle == typename objnull) then {_vehicle = typeof _vehicle;};

_cfgVehicle = configfile >> "cfgvehicles" >> _vehicle;


private _path = []; 
_fnc_getTurretindex = {    
params[ "_cfg" ];    
	{  
		
		if !(call _condition) then   
		{   
			_path append [_forEachIndex]; 
			_roles pushBack ["Turret",+_path]; 

		} else { 
			_path append [_forEachIndex]; 
			_roles pushBack ["CargoTurret",+_path]; 
		}; 
	   
		if (isclass (_x >> "turrets")) then   
			{
			_x call _fnc_getTurretindex;  
			_path deleteAt (count _path - 1); 
			};  
	}forEach ( "true" configClasses( _cfg >> "turrets" ));
	    
_roles;  
    
};
private _condition = {getNumber (_x >> "showAsCargo") isEqualto 1};
_cfgVehicle call _fnc_getTurretindex;


for "_t" from 0 to (getnumber (_cfgVehicle >> "transportsoldier") - 1) do { 
	_roles pushBack ["Cargo",[_t]];  
};

if (getnumber (_cfgVehicle >> "hasdriver") isEqualTo 1) then {
	_roles pushBack ["Driver",[]]; 
};

_roles
};

 

["CUP_O_T72_TKA"] call TAG_fnc_getTurretIndex;
//[["Turret",[0]],["Turret",[0,0]],["CargoTurret",[1]],["CargoTurret",[2]],["CargoTurret",[3]],["CargoTurret",[4]],["CargoTurret",[5]],["CargoTurret",[6]],["Driver",[]]]

["B_T_Truck_01_transport_F"] call TAG_fnc_getTurretIndex;
//[["CargoTurret",[0]],["CargoTurret",[1]],["Driver",[]],["Cargo",[0]],["Cargo",[1]],["Cargo",[2]],["Cargo",[3]],["Cargo",[4]],["Cargo",[5]],["Cargo",[6]],["Cargo",[7]],["Cargo",[8]],["Cargo",[9]],["Cargo",[10]],["Cargo",[11]],["Cargo",[12]],["Cargo",[13]],["Cargo",[14]]]

["B_MBT_01_cannon_f"] call TAG_fnc_getTurretIndex;
//[["Turret",[0]],["Turret",[0,0]],["Driver",[]],["Cargo",[0]],["Cargo",[1]],["Cargo",[2]],["Cargo",[3]],["Cargo",[4]],["Cargo",[5]]]

cargoturrets are considered turrets so use moveinturret.  moveindriver, moveincargo for the respective array names.

 

Spoiler

_grp = createGroup west;
	_vehPositions=["B_T_Truck_01_transport_F"] call TAG_fnc_getVehiclePosition;
	_vehicle = createVehicle ["B_T_Truck_01_transport_F", getpos player, [], 0, "CAN_COLLIDE"];

_vehCrew=[];

		{
	_currentPosition=_x;
	if (_currentPosition select 0 == "driver")then {
			_unit = _grp createUnit ["b_crew_f", (getpos player), [], 0, "CAN_COLLIDE"];					
			_unit moveInDriver _vehicle;
			_vehCrew set [count _vehCrew,_unit];
			};
	
	if (_currentPosition select 0 == "CargoTurret")then {
			_unit = _grp createUnit ["b_soldier_AR_f", (getpos player), [], 0, "CAN_COLLIDE"];
			_unit MoveInTurret [_vehicle,_currentPosition select 1];
			_vehCrew set [count _vehCrew,_unit];
			};
	
		if (_currentPosition select 0 == "Cargo")then {
			_unit = _grp createUnit ["b_soldier_f", (getpos player), [], 0, "CAN_COLLIDE"];
			_unit moveInCargo [_vehicle,(_currentPosition select 1)select 0];
			};
			
		}foreach _vehPositions;

 

 

Share this post


Link to post
Share on other sites
Spoiler

fn_instring={
 params ["_fstr","_instr"];

 _fstr = toArray (_fstr);
 _instr = toArray (_instr);
 _idx = 0;
 _m = false;
 _d = count(_fstr);

 for "_i" from 0 to count(_instr)-1 do
 {
  if !((_instr select _i) isEqualTo (_fstr select _idx)) then {_idx=0;
  }else{
  _idx=_idx+1; 
  if (_idx isEqualTo _d) exitwith {_m = true; };
  };
  
  
 };
_m;
}; ["hi","1hi1"] call fn_instring;

 

my slow instring fnc

Result:
0.0126 ms

Cycles:
10000/10000

["hi","1hi1"] call fn_instring; //returns true

 

 

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
Sign in to follow this  

×