Jump to content
sizraide

Checking if classname loadout has any weapons.

Recommended Posts

Hello, I have a script here that checks if the classname provided has any primary, secondary, or handgun.

This script works sometimes, when it doesn't, it gets an error for Error Zero Divisor

Script:

// Check if unit has any weapons.
_weapons = getUnitLoadout _classname select [0,3];
if((_weapons select 0) isEqualTo [] && (_weapons select 1) isEqualTo [] && (_weapons select 2) isEqualTo []) exitWith { false };

 

Any help is appreciated.

Share this post


Link to post
Share on other sites

What's the value of _classname when it fails? Perhaps getUnitLoadout doesn't return array in the expected format for some inputs.

Share this post


Link to post
Share on other sites
5 hours ago, _foley said:

What's the value of _classname when it fails? Perhaps getUnitLoadout doesn't return array in the expected format for some inputs.

It's put into a variable to check how many units are in a faction are suitable for the scenario.

It's part of a larger function to collect every faction from CfgFactionClasses and determine if a faction is usable in a scenario based on how many amount of units are appropriate for the scenario.

_index = { [configName _x] call SIZ_fnc_checkUnit } count ("(configName _x isKindOf 'Man') && getText (_x >> 'faction') == _faction" configClasses (configFile >> "CfgVehicles"));


Here is the full function.
 

_factions = [];
{
	_faction = configName _x;
	_index = { [configName _x] call SIZ_fnc_checkUnit } count ("(configName _x isKindOf 'Man') && getText (_x >> 'faction') == _faction" configClasses (configFile >> "CfgVehicles"));

	if(_index > 2) then { 
		_displayName = getText (configFile >> "CfgFactionClasses" >> _faction >> "displayName");
		if(_displayName isNotEqualTo "") then {

			_icon = getText (configFile >> "CfgFactionClasses" >> _faction >> "icon");
			_side = getNumber (configFile >> "CfgFactionClasses" >> _faction >> "side");

			if(_icon == "") then 
			{
				switch(_side) do 
				{
					case 0: {_icon = "a3\data_f\flags\flag_red_co.paa"};
					case 1: {_icon = "a3\data_f\flags\flag_blue_co.paa"};
					case 2: {_icon = "a3\data_f\flags\flag_green_co.paa"};
				};
			};
			_factions set [_forEachIndex, [_displayName, _faction, _side, _icon]];
		};
	};
} forEach ("getNumber (_x >> 'side') in [0,1,2,3]" configClasses (configFile >> "CfgFactionClasses"));


EDIT:

I forgot to mention SIZ_fnc_checkUnit is where the classname is sent through.

Share this post


Link to post
Share on other sites

Use params on the data instead of select, so you can give it some defaults if the data doesn't exist. Then you won't get any indexing errors.

getUnitLoadout _classname params[ [ "_primaryDetails", [] ], [ "_secondaryDetails", [] ], [ "_handGunDetails", [] ] ];
_primaryDetails params[ [ "_primaryWeapon", "" ] ];
_secondaryDetails params[ [ "_secondaryWeapon", "" ] ];
_handGunDetails params[ [ "_handGun", "" ] ];

if ( _primaryWeapon == "" && _secondaryWeapon == "" && _handGun == "" ) exitWith { false };

 

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

×