Jump to content

Recommended Posts

HI.

Maybe someone can find this usable.

Iterate trough config weapon classes and returns array of weapons/ammo according to given parameters

 

/*
file : fnc_getWeapon.sqf
author: DaVidoSS
description: Iterate trough config weapon classes and returns array of weapons/ammo according to given parameters
parameters:
0: STRING

one from listed below
"assault"  
"handgun"		
"submachine" 
"rocket launcher"
"missile launcher"
"grenade launcher"	
"light machine"
"medium machine"
"marksman"
"sniper"
"all"

1: SCALAR or STRING
"all" for all available classes of param 0
NUMBER classes of param 0 

2: BOOLEAN
true - for return ammo classes too in form ["weapon",["ammo","ammo"...]]
false - for return without ammo classes in form ["weapon","weapon"...]

Return: ARRAY

Usage:
fnc_getWeapon = compileFinal preprocessFileLineNumbers "fnc_getWeapon.sqf";

_10assaultGunsWithAmmo =  ["assault" ,10,true] call fnc_getWeapon;
_1MarksmanGunWithoutAmmo =  ["marksman" ,1,false] call fnc_getWeapon;
_allGunsofAllTypeWithAmmo = ["all","all",true] call fnc_getWeapon;
*/

private _paramsCheck = params [["_type","all",[""]],["_allof","all",["",0]],["_withMags",false,[true]]];
if (!_paramsCheck) exitWith {["***********ERROR:fnc_getWeapon - exiting due wrong params given %1",str _this] call BIS_fnc_error; false};
private _array = [];
private _return = [];
{
	private _class = (configName _x);
	if (getNumber (configfile >> "CfgWeapons" >> _class >> "type") < 5) then {
		private _magazines = getArray (configfile >> "CfgWeapons" >> _class >> "magazines");
		private _name = toLower (getText (configfile >> "CfgWeapons" >> _class >> "descriptionShort"));
		if !(_magazines isEqualTo []) then {
			if (toLower _type != "all") then {
				if ((_name find (toLower _type)) > -1) then {
					if (_withMags) then {
						_array pushBack [_class,_magazines];
					} else {
						_array pushBack _class;
					};
				};
			} else {
			
				if (_withMags) then {
					_array pushBack [_class,_magazines];
				} else {
					_array pushBack _class;
				};
			};
		};
	};

} forEach ("isClass _x && {(getNumber (_x >> 'scope')) isEqualTo 2}" configClasses (configfile >> "CfgWeapons"));
	
switch (true) do {
	case (_allof isEqualType 0): {
		if (_allof isEqualTo 1) exitWith {
			_return pushBack (selectRandom _array);	
		};
		if (_allof > 1 && {count _array >= _allof}) then {
			for "_i" from 1 to _allof do {
				_return pushBackUnique (selectRandom (_array - _return));					
			};	
		} else {
			if (_allof < 1) exitWith {_return pushBack (selectRandom _array)};
			_return = _array;
		};
	};		
	case (_allof isEqualType ""): {
		_return = _array;
	};	
	default {};
};
(_return)

Enjoy :-)

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you very much davidoss !

 

This is another nice script !

PS: i think you should compile them in a topic .  :f:

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

×