From 21f328f227ba1f3a68606ab5b83321a7a1090e2f Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 10 May 2016 23:36:07 +0200 Subject: [PATCH 1/6] add CBA_fnc_binocularMagazine --- addons/common/CfgFunctions.hpp | 1 + addons/common/fnc_binocularMagazine.sqf | 36 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 addons/common/fnc_binocularMagazine.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 4e2f4d7a5..8c157d0d8 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -67,6 +67,7 @@ class CfgFunctions { F_FILEPATH(dropWeapon); F_FILEPATH(dropMagazine); F_FILEPATH(dropItem); + F_FILEPATH(binocularMagazine); }; class Cargo { 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 From dfad3c47cd29f586647294946a764c209ccabeb2 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 10 May 2016 23:47:26 +0200 Subject: [PATCH 2/6] add CBA_fnc_removeBinocularMagazine --- addons/common/CfgFunctions.hpp | 1 + addons/common/fnc_removeBinocularMagazine.sqf | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 addons/common/fnc_removeBinocularMagazine.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 8c157d0d8..871d56b4f 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -68,6 +68,7 @@ class CfgFunctions { F_FILEPATH(dropMagazine); F_FILEPATH(dropItem); F_FILEPATH(binocularMagazine); + F_FILEPATH(removeBinocularMagazine); }; class Cargo { 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; +}; From 6f8211744c5dbdcce4402130f547bb11674b899f Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 11 May 2016 00:17:04 +0200 Subject: [PATCH 3/6] add CBA_fnc_addBinocularMagazine --- addons/common/CfgFunctions.hpp | 1 + addons/common/fnc_addBinocularMagazine.sqf | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 addons/common/fnc_addBinocularMagazine.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 871d56b4f..77de22342 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -68,6 +68,7 @@ class CfgFunctions { F_FILEPATH(dropMagazine); F_FILEPATH(dropItem); F_FILEPATH(binocularMagazine); + F_FILEPATH(addBinocularMagazine); F_FILEPATH(removeBinocularMagazine); }; diff --git a/addons/common/fnc_addBinocularMagazine.sqf b/addons/common/fnc_addBinocularMagazine.sqf new file mode 100644 index 000000000..fdfb30cbb --- /dev/null +++ b/addons/common/fnc_addBinocularMagazine.sqf @@ -0,0 +1,41 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addBinocularMagazine + +Description: + Adds a magazine to the units rangefinder. + +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; + +private _binocularInfo = _loadout param [8]; +_binocularInfo set [4, [_magazine, _ammo]]; +_loadout set [8, _binocularInfo]; + +_unit setUnitLoadout _loadout; From e0a72b43b092b953ab0b1f6b175016265b04bb41 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 11 May 2016 00:19:20 +0200 Subject: [PATCH 4/6] add note/warning about magazine IDs --- addons/common/fnc_addBinocularMagazine.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/common/fnc_addBinocularMagazine.sqf b/addons/common/fnc_addBinocularMagazine.sqf index fdfb30cbb..5180df67c 100644 --- a/addons/common/fnc_addBinocularMagazine.sqf +++ b/addons/common/fnc_addBinocularMagazine.sqf @@ -3,6 +3,7 @@ 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 From 7ad1e38e1c085603d64e147271e18a9d270348f9 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 11 May 2016 00:31:05 +0200 Subject: [PATCH 5/6] simplify --- addons/common/fnc_addBinocularMagazine.sqf | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/common/fnc_addBinocularMagazine.sqf b/addons/common/fnc_addBinocularMagazine.sqf index 5180df67c..9e8dcb202 100644 --- a/addons/common/fnc_addBinocularMagazine.sqf +++ b/addons/common/fnc_addBinocularMagazine.sqf @@ -34,9 +34,6 @@ if (isNil "_ammo") then { }; private _loadout = getUnitLoadout _unit; - -private _binocularInfo = _loadout param [8]; -_binocularInfo set [4, [_magazine, _ammo]]; -_loadout set [8, _binocularInfo]; +(_loadout select 8) set [4, [_magazine, _ammo]]; _unit setUnitLoadout _loadout; From c67b52cdd322e8fb233f72cce748a86c8322c2c5 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 15 May 2016 11:16:24 +0200 Subject: [PATCH 6/6] add empty line to function header for function description expport script --- addons/common/fnc_addBinocularMagazine.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/common/fnc_addBinocularMagazine.sqf b/addons/common/fnc_addBinocularMagazine.sqf index 9e8dcb202..53a536a8b 100644 --- a/addons/common/fnc_addBinocularMagazine.sqf +++ b/addons/common/fnc_addBinocularMagazine.sqf @@ -3,6 +3,7 @@ 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: