diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 4e2f4d7a5..77de22342 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -67,6 +67,9 @@ class CfgFunctions { F_FILEPATH(dropWeapon); F_FILEPATH(dropMagazine); F_FILEPATH(dropItem); + F_FILEPATH(binocularMagazine); + F_FILEPATH(addBinocularMagazine); + F_FILEPATH(removeBinocularMagazine); }; class Cargo { diff --git a/addons/common/fnc_addBinocularMagazine.sqf b/addons/common/fnc_addBinocularMagazine.sqf new file mode 100644 index 000000000..53a536a8b --- /dev/null +++ b/addons/common/fnc_addBinocularMagazine.sqf @@ -0,0 +1,40 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addBinocularMagazine + +Description: + Adds a magazine to the units rangefinder. + + Note that this breaks the unique magazine ids due to the usage of setUnitLoadout. + +Parameters: + _unit - A unit + _magazine - The magazine to add + _ammo - Ammo count of the magazine (optional, default: full magazine) + +Returns: + None + +Examples: + (begin example) + player addWeapon "Laserdesignator"; + [player, "Laserbatteries"] call CBA_fnc_addBinocularMagazine; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(addBinocularMagazine); + +params [["_unit", objNull, [objNull]], ["_magazine", "", [""]], ["_ammo", nil, [0]]]; + +if (!local _unit) exitWith {}; + +if (isNil "_ammo") then { + _ammo = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); +}; + +private _loadout = getUnitLoadout _unit; +(_loadout select 8) set [4, [_magazine, _ammo]]; + +_unit setUnitLoadout _loadout; diff --git a/addons/common/fnc_binocularMagazine.sqf b/addons/common/fnc_binocularMagazine.sqf new file mode 100644 index 000000000..2ce6d9dd2 --- /dev/null +++ b/addons/common/fnc_binocularMagazine.sqf @@ -0,0 +1,36 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_binocularMagazine + +Description: + Returns the magazine of the units rangefinder. + +Parameters: + _unit - A unit + +Returns: + Magazine of the units binocular + +Examples: + (begin example) + player call CBA_fnc_binocularMagazine + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(binocularMagazine); + +params [["_unit", objNull, [objNull]]]; + +private _binocular = binocular _unit; +private _magazine = ""; + +{ + if ((_x select 0) isEqualTo _binocular) exitWith { + // note: if there is no magazine, _x(4,0) will be nil + _magazine = (_x select 4) param [0, ""]; + }; +} forEach weaponsitems _unit; + +_magazine diff --git a/addons/common/fnc_removeBinocularMagazine.sqf b/addons/common/fnc_removeBinocularMagazine.sqf new file mode 100644 index 000000000..c1d39c6ff --- /dev/null +++ b/addons/common/fnc_removeBinocularMagazine.sqf @@ -0,0 +1,35 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_removeBinocularMagazine + +Description: + Removes the magazine of the units rangefinder. + +Parameters: + _unit - A unit + +Returns: + None + +Examples: + (begin example) + player call CBA_fnc_removeBinocularMagazine + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(removeBinocularMagazine); + +params [["_unit", objNull, [objNull]]]; + +if (!local _unit) exitWith {}; + +private _binocular = binocular _unit; +private _selectBinocular = currentWeapon _unit isEqualTo _binocular; + +_unit addWeapon _binocular; + +if (_selectBinocular) then { + _unit selectWeapon _binocular; +};