From 44e0fdb6fa1ce2879587b927084ee1d8b828e444 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 28 Aug 2023 19:26:24 +0200 Subject: [PATCH] Reload - Code cleanup and various improvements (#9343) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Reload code cleanup * Update fnc_startLinkingBelt.sqf * Update addons/reload/functions/fnc_getAmmoToLinkBelt.sqf Co-authored-by: Jouni Järvinen --------- Co-authored-by: Jouni Järvinen --- addons/common/initSettings.sqf | 2 +- addons/laserpointer/initSettings.sqf | 2 +- addons/reload/CfgEventHandlers.hpp | 1 - addons/reload/CfgVehicles.hpp | 14 +-- addons/reload/XEH_PREP.hpp | 1 - addons/reload/XEH_postInit.sqf | 62 +++++------- addons/reload/functions/fnc_canCheckAmmo.sqf | 28 ++---- .../reload/functions/fnc_canCheckAmmoSelf.sqf | 4 +- addons/reload/functions/fnc_checkAmmo.sqf | 17 ++-- addons/reload/functions/fnc_displayAmmo.sqf | 98 +++++++++++-------- .../functions/fnc_getAmmoToLinkBelt.sqf | 21 ++-- addons/reload/functions/fnc_onTake.sqf | 14 +-- .../reload/functions/fnc_startLinkingBelt.sqf | 53 +++++----- addons/reload/initKeybinds.sqf | 16 +++ addons/reload/initSettings.sqf | 11 +-- addons/reload/stringtable.xml | 10 ++ addons/weaponselect/initSettings.sqf | 2 +- 17 files changed, 188 insertions(+), 168 deletions(-) create mode 100644 addons/reload/initKeybinds.sqf diff --git a/addons/common/initSettings.sqf b/addons/common/initSettings.sqf index b0329732ff..e6b8b73248 100644 --- a/addons/common/initSettings.sqf +++ b/addons/common/initSettings.sqf @@ -68,7 +68,7 @@ private _categoryColors = [_category, format ["| %1 |", LLSTRING(subcategory_col QGVAR(persistentLaserEnabled), "CHECKBOX", [LSTRING(SettingPersistentLaserName), LSTRING(SettingPersistentLaserDesc)], - localize LSTRING(ACEKeybindCategoryWeapons), + LSTRING(ACEKeybindCategoryWeapons), false, false, LINKFUNC(switchPersistentLaser) diff --git a/addons/laserpointer/initSettings.sqf b/addons/laserpointer/initSettings.sqf index edf9138b7b..8e1d3bf425 100644 --- a/addons/laserpointer/initSettings.sqf +++ b/addons/laserpointer/initSettings.sqf @@ -1,7 +1,7 @@ [ QGVAR(enabled), "CHECKBOX", LSTRING(DisplayName), - localize ELSTRING(common,ACEKeybindCategoryWeapons), + ELSTRING(common,ACEKeybindCategoryWeapons), true, 1 ] call CBA_fnc_addSetting; diff --git a/addons/reload/CfgEventHandlers.hpp b/addons/reload/CfgEventHandlers.hpp index 13d082c8bf..f76ea983d1 100644 --- a/addons/reload/CfgEventHandlers.hpp +++ b/addons/reload/CfgEventHandlers.hpp @@ -1,4 +1,3 @@ - class Extended_PreStart_EventHandlers { class ADDON { init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); diff --git a/addons/reload/CfgVehicles.hpp b/addons/reload/CfgVehicles.hpp index f6723510e0..ff0df195d3 100644 --- a/addons/reload/CfgVehicles.hpp +++ b/addons/reload/CfgVehicles.hpp @@ -14,16 +14,16 @@ class CfgVehicles { class ACE_Actions { class ACE_Weapon { - class GVAR(LinkBelt) { - displayName = CSTRING(LinkBelt); - distance = 2.0; + class GVAR(linkBelt) { + displayName = CSTRING(linkBelt); + distance = 2; condition = QUOTE(([ARR_2(_player, _target)] call FUNC(getAmmoToLinkBelt)) > 0); statement = QUOTE([ARR_2(_player, _target)] call FUNC(startLinkingBelt)); exceptions[] = {"isNotInside"}; }; - class GVAR(CheckAmmo) { + class GVAR(checkAmmo) { displayName = CSTRING(checkAmmo); - distance = 2.0; + distance = 2; condition = QUOTE(call FUNC(canCheckAmmo)); statement = QUOTE(call FUNC(checkAmmo)); exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"}; @@ -36,9 +36,9 @@ class CfgVehicles { class StaticWeapon: LandVehicle { class ACE_Actions { class ACE_MainActions { - class GVAR(CheckAmmo) { + class GVAR(checkAmmo) { displayName = CSTRING(checkAmmo); - distance = 2.0; + distance = 2; condition = QUOTE(call FUNC(canCheckAmmo)); statement = QUOTE(call FUNC(checkAmmo)); exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"}; diff --git a/addons/reload/XEH_PREP.hpp b/addons/reload/XEH_PREP.hpp index 20fc53724e..578bc2ce9f 100644 --- a/addons/reload/XEH_PREP.hpp +++ b/addons/reload/XEH_PREP.hpp @@ -1,4 +1,3 @@ - PREP(canCheckAmmo); PREP(canCheckAmmoSelf); PREP(getAmmoToLinkBelt); diff --git a/addons/reload/XEH_postInit.sqf b/addons/reload/XEH_postInit.sqf index 26f7f303ff..65ce1d0b4b 100644 --- a/addons/reload/XEH_postInit.sqf +++ b/addons/reload/XEH_postInit.sqf @@ -1,63 +1,55 @@ // by esteldunedain #include "script_component.hpp" -if (!hasInterface) exitWith {}; - -// Add keybinds -["ACE3 Weapons", QGVAR(checkAmmo), localize LSTRING(checkAmmo), { - // Conditions: canInteract - if !([ACE_player, vehicle ACE_player, ["isNotInside", "isNotSwimming", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - if !(ACE_player call FUNC(canCheckAmmoSelf)) exitWith {false}; - // Ignore if controlling UAV (blocks radar keybind) - if (!isNull (ACE_controlledUAV param [0, objNull])) exitWith {false}; - - // Statement - [ACE_player, ACE_player] call FUNC(checkAmmo); - true -}, {false}, [19, [false, true, false]], false] call CBA_fnc_addKeybind; - +// To propagate the setAmmo change, do it on all clients +// See https://github.com/acemod/ACE3/issues/1119 and https://feedback.bistudio.com/T167015 [QGVAR(syncAmmo), { - //To propagate the setAmmo change, do it on all clients params ["_unit", "_weapon", "_ammo"]; TRACE_3("syncAmmo EH",_unit,_weapon,_ammo); - _unit setAmmo [_weapon, _ammo]; }] call CBA_fnc_addEventHandler; // Listen for attempts to link ammo [QGVAR(ammoLinked), { - params ["_receiver", "_giver", "_magazine"]; - - private _magazineType = currentMagazine _receiver; - private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; + params ["_target", "_unit", "_magazineInfo"]; + _magazineInfo params ["_magazine", "_ammo"]; // Return the magazine if it's the wrong type - if (_magazineType != (_magazine select 0)) exitWith { - [QGVAR(ammoReturned), [_giver,_receiver,_magazine], [_giver]] call CBA_fnc_targetEvent; + if (currentMagazine _target != _magazine) exitWith { + [QGVAR(ammoReturned), [_unit, _target, _magazineInfo, false], _unit] call CBA_fnc_targetEvent; }; - private _ammoCount = _receiver ammo currentWeapon _receiver; - private _ammoMissing = getNumber (_magazineCfg >> "count") - _ammoCount; + private _currentWeapon = currentWeapon _target; + private _currentAmmo = _target ammo _currentWeapon; + private _magazineCfg = configFile >> "CfgMagazines" >> _magazine; + private _ammoMissing = getNumber (_magazineCfg >> "count") - _currentAmmo; // Return the magazine if the belt is full or empty - if ((_ammoCount == 0) || _ammoMissing == 0) exitWith { - [QGVAR(ammoReturned), [_giver,_receiver,_magazine], [_giver]] call CBA_fnc_targetEvent; + if (_currentAmmo == 0 || {_ammoMissing == 0}) exitWith { + [QGVAR(ammoReturned), [_unit, _target, _magazineInfo, false], _unit] call CBA_fnc_targetEvent; }; // Add the ammo - private _ammoAdded = _ammoMissing min (_magazine select 1); - [QGVAR(syncAmmo), [_receiver, currentWeapon _receiver, _ammoCount + _ammoAdded]] call CBA_fnc_globalEvent; + private _ammoAdded = _ammoMissing min _ammo; + [QGVAR(syncAmmo), [_target, _currentWeapon, _currentAmmo + _ammoAdded]] call CBA_fnc_globalEvent; - if ((_magazine select 1) - _ammoAdded > 0) then { - [QGVAR(ammoReturned), [_giver, _receiver, [_magazineType, (_magazine select 1) - _ammoAdded]], [_giver]] call CBA_fnc_targetEvent; + // Return left over ammo to reloading unit + if (_ammo - _ammoAdded > 0) then { + [QGVAR(ammoReturned), [_unit, _target, [_magazine, _ammo - _ammoAdded], true], _unit] call CBA_fnc_targetEvent; }; }] call CBA_fnc_addEventHandler; // Listen for returned magazines [QGVAR(ammoReturned), { - params ["_receiver", "", "_magazine"]; - TRACE_2("ammoReturned EH",_receiver,_magazine); + params ["_unit", "_target", "_magazineInfo", "_success"]; + TRACE_3("ammoReturned EH",_unit,_target,_magazineInfo); - _receiver addMagazine _magazine; + // If inventory is full, magazine will be dropped on the ground + [_unit, _magazineInfo select 0, _magazineInfo select 1, true] call CBA_fnc_addMagazine; + + [[LSTRING(BeltNotLinked), LSTRING(BeltLinked)] select _success] call EFUNC(common,displayTextStructured); }] call CBA_fnc_addEventHandler; + +if (!hasInterface) exitWith {}; + +#include "initKeybinds.sqf" diff --git a/addons/reload/functions/fnc_canCheckAmmo.sqf b/addons/reload/functions/fnc_canCheckAmmo.sqf index 9632d0b4b1..652e521ec7 100644 --- a/addons/reload/functions/fnc_canCheckAmmo.sqf +++ b/addons/reload/functions/fnc_canCheckAmmo.sqf @@ -1,13 +1,13 @@ #include "script_component.hpp" /* - * Author: CAA-Picard - * Check if the player can check the ammo of the target. + * Author: CAA-Picard, johnb43 + * Check if a unit can check the ammo of the target. * * Arguments: - * 0: Target + * 0: Unit equipped with the weapon * * Return Value: - * Can link belt + * Can check ammo * * Example: * [cursorObject] call ace_reload_fnc_canCheckAmmo @@ -17,26 +17,18 @@ params ["_target"]; -// Return true for static weapons if they have been fired once, @todo 1.40 this work-around doesn't work anymore +// Static weapons if (_target isKindOf "StaticWeapon") exitWith { - if (currentMagazine _target != "") exitWith {true}; - - // no check ammo action on destroyed static weapons + // No check ammo action on destroyed static weapons if (!alive _target) exitWith {false}; - private _found = false; + if (currentMagazine _target != "") exitWith {true}; - { - if (_x select 2) exitWith { - _found = true; - }; - false - } count magazinesAmmoFull _target; - - _found + // Check for loaded magazines + (magazinesAmmoFull _target) findIf {_x select 2} != -1 }; -// Return false for all other vehicles +// All other vehicles if !(_target isKindOf "CAManBase") exitWith {false}; // For men diff --git a/addons/reload/functions/fnc_canCheckAmmoSelf.sqf b/addons/reload/functions/fnc_canCheckAmmoSelf.sqf index 2c8c03dcce..14439af09f 100644 --- a/addons/reload/functions/fnc_canCheckAmmoSelf.sqf +++ b/addons/reload/functions/fnc_canCheckAmmoSelf.sqf @@ -7,10 +7,10 @@ * 0: Player * * Return Value: - * Can check ammo + * Can check ammo for self * * Example: - * [cursorObject] call ace_reload_fnc_canCheckAmmoSelf + * [player] call ace_reload_fnc_canCheckAmmoSelf * * Public: No */ diff --git a/addons/reload/functions/fnc_checkAmmo.sqf b/addons/reload/functions/fnc_checkAmmo.sqf index 995e72dc3f..aa55edf3d1 100644 --- a/addons/reload/functions/fnc_checkAmmo.sqf +++ b/addons/reload/functions/fnc_checkAmmo.sqf @@ -1,11 +1,11 @@ #include "script_component.hpp" /* - * Author: commy2 and esteldunedain - * Count the ammo of the currently loaded magazine or count rifle grenades. Play animation and display message. + * Author: commy2, esteldunedain + * Play animation and display message. * * Arguments: - * 0: Target. - * 1: Player + * 0: Unit equipped with the weapon + * 1: Unit to execute the reload * * Return Value: * None @@ -16,13 +16,14 @@ * Public: No */ -params ["_target", "_player"]; +params ["_target", "_unit"]; -if (_player == _target) then { +if (_unit == _target) then { if ((vehicle _target) isKindOf "StaticWeapon") then { _target = vehicle _target; }; - [_player, "Gear", 1] call EFUNC(common,doGesture); + + [_unit, "Gear", 1] call EFUNC(common,doGesture); }; -[FUNC(displayAmmo), [_target], 1] call CBA_fnc_waitAndExecute; +[FUNC(displayAmmo), _target, 1] call CBA_fnc_waitAndExecute; diff --git a/addons/reload/functions/fnc_displayAmmo.sqf b/addons/reload/functions/fnc_displayAmmo.sqf index 329c385935..06da24a7e4 100644 --- a/addons/reload/functions/fnc_displayAmmo.sqf +++ b/addons/reload/functions/fnc_displayAmmo.sqf @@ -1,16 +1,16 @@ #include "script_component.hpp" /* - * Author: commy2 and esteldunedain + * Author: commy2, esteldunedain * Display the ammo of the currently loaded magazine of the target or count rifle grenades. * * Arguments: - * 0: Target + * 0: Unit equipped with the weapon * * Return Value: * None * * Example: - * player call ace_reload_fnc_displayAmmo + * [player] call ace_reload_fnc_displayAmmo * * Public: No */ @@ -21,59 +21,58 @@ params ["_target"]; private _isStaticWeapon = _target isKindOf "StaticWeapon"; -if (_isStaticWeapon) then { - [currentWeapon _target, currentMuzzle _target, "", currentMagazine _target] -} else { - weaponState _target -} params ["_weapon", "_muzzle", "", "_magazine"]; +// currentWeapon, currentMagazine and weaponState return "" for static weapons before they have been entered once +(if (_isStaticWeapon) then { + private _weapon = currentWeapon _target; -// currentWeapon returns "" for static weapons before they are shot once -if (_isStaticWeapon) then { if (_weapon == "") then { - if (count (weapons _target) == 1) then { - _weapon = (weapons _target) select 0; - _muzzle = _weapon; + private _weapons = weapons _target; + + if (count _weapons == 1) then { + _weapon = _weapons select 0; }; }; + private _magazine = currentMagazine _target; + if (_magazine == "") then { // Try to get magazine using magazinesAmmoFull - private _magazines = magazinesAmmoFull _target; - { if (_x select 2) exitWith { _magazine = _x select 0; }; - } forEach _magazines; + } forEach magazinesAmmoFull _target; }; - // For static weapons the muzzle seemingly never returns anything for static weapons with/without people inside - if (_muzzle == "") then { - _muzzle = _weapon; - }; -}; + // currentMuzzle always returns "" + [_weapon, _weapon, "", _magazine] +} else { + weaponState _target +}) params ["_weapon", "_muzzle", "", "_magazine"]; TRACE_3("",_weapon,_muzzle,_magazine); -if ("" in [_weapon, _magazine]) exitWith {}; +if ("" == _weapon) exitWith {}; private _ammo = _target ammo _muzzle; -private _magazineConfig = configFile >> "CfgMagazines" >> _magazine; -private _maxRounds = getNumber (_magazineConfig >> "count") max 1; +private _magazineCfg = configFile >> "CfgMagazines" >> _magazine; +private _maxRounds = getNumber (_magazineCfg >> "count") max 1; private _count = -1; // Show a count instead of ammo bars (ignore if -1) -if (_muzzle != _weapon) then { - // grenade launcher (or some kind of seconday muzzle) - if (_ammo > 0) then { - if (_maxRounds == 1) then { // singleShot so show count of identical mags available instead of ammo bars - _count = 1 + ({_x == _magazine} count magazines _target); - }; - } else { - if (_maxRounds <= 3) then { // empty GL/3GL - don't have a real magazine so just show count of any compatible mag - _magazine = ""; - private _compatibleMagazines = [configFile >> "CfgWeapons" >> _weapon >> _muzzle] call CBA_fnc_compatibleMagazines; - _count = {_x in _compatibleMagazines} count (magazines _target); // safe because everything is config case - }; +// If secondary muzzle is selected or no magazine in current muzzle +if (_muzzle != _weapon || {_magazine == ""}) then { + // Check if no or empty magazine; If true, just show count of compatible magazines + if (_ammo == 0) exitWith { + _magazine = ""; // Make sure, as it could also be secondary muzzle being selected + + private _compatibleMagazines = compatibleMagazines [_weapon, _muzzle]; + + _count = {_x in _compatibleMagazines} count (magazines _target); + }; + + // singleShot, so show count of identical mags available instead of ammo bars + if (_ammo > 0 && {_maxRounds == 1}) exitWith { + _count = 1 + ({_x == _magazine} count (magazines _target)); }; }; @@ -83,21 +82,29 @@ private _ammoBarsStructuredText = if (_count >= 0) then { if (_maxRounds >= COUNT_BARS) then { _count = round (COUNT_BARS * _ammo / _maxRounds); - if (_ammo > 0) then {_count = _count max 1}; - if (_ammo < _maxRounds) then {_count = _count min (COUNT_BARS - 1)}; + if (_ammo > 0) then { + _count = _count max 1; + }; + + if (_ammo < _maxRounds) then { + _count = _count min (COUNT_BARS - 1); + }; } else { _count = _ammo; }; - private _color = [((2 * (1 - _ammo / _maxRounds)) min 1), ((2 * _ammo / _maxRounds) min 1), 0]; + private _color = [(2 * (1 - _ammo / _maxRounds)) min 1, (2 * _ammo / _maxRounds) min 1, 0]; private _string = ""; + for "_a" from 1 to _count do { _string = _string + "|"; }; + private _text = [_string, _color] call EFUNC(common,stringToColoredText); _string = ""; + for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do { _string = _string + "|"; }; @@ -105,16 +112,21 @@ private _ammoBarsStructuredText = if (_count >= 0) then { composeText [_text, [_string, "#808080"] call EFUNC(common,stringToColoredText)]; }; - if (_isStaticWeapon) then { - //Vehicle mags (usualy) don't have pictures, so just show the text above ammo count - private _loadedName = getText (_magazineConfig >> "displaynameshort"); + // Vehicle mags usually don't have pictures, so just show the text above ammo count + private _loadedName = getText (_magazineCfg >> "displayNameShort"); + + if (_loadedName == "") then { + _loadedName = getText (_magazineCfg >> "displayName"); + }; + _loadedName = parseText format ["%1", _loadedName]; + private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText]; [_text] call EFUNC(common,displayTextStructured); } else { if (_magazine != "") then { - private _picture = getText (_magazineConfig >> "picture"); + private _picture = getText (_magazineCfg >> "picture"); [_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture); } else { [_ammoBarsStructuredText, 1] call EFUNC(common,displayTextStructured); diff --git a/addons/reload/functions/fnc_getAmmoToLinkBelt.sqf b/addons/reload/functions/fnc_getAmmoToLinkBelt.sqf index 3701b32d8b..3433e81ec1 100644 --- a/addons/reload/functions/fnc_getAmmoToLinkBelt.sqf +++ b/addons/reload/functions/fnc_getAmmoToLinkBelt.sqf @@ -1,11 +1,11 @@ #include "script_component.hpp" /* * Author: esteldunedain, phyma - * Check if the target has an MG equiped with belt system that the player can link + * Check if the target has an MG equipped with belt system that a unit can link. * * Arguments: - * 0: Player - * 1: Target + * 0: Unit wanting to execute the reload + * 1: Unit equipped with the weapon * * Return Value: * Maximum ammo of magazine (-1 on error) @@ -16,12 +16,12 @@ * Public: No */ -params ["_player", "_target"]; +params ["_unit", "_target"]; -if (vehicle _target != _target) exitWith {-1}; +if !(isNull objectParent _target) exitWith {-1}; -private _magazineType = currentMagazine _target; -private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; +private _magazine = currentMagazine _target; +private _magazineCfg = configFile >> "CfgMagazines" >> _magazine; if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {-1}; @@ -29,14 +29,13 @@ if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {-1}; private _ammoCount = _target ammo currentWeapon _target; // Exit if the belt is full or empty -if (_ammoCount == 0 || getNumber (_magazineCfg >> "count") - _ammoCount == 0) exitWith {-1}; +if (_ammoCount == 0 || {getNumber (_magazineCfg >> "count") - _ammoCount == 0}) exitWith {-1}; -// Check if the player has any of the same magazines -// Calculate max ammo +// Check if the unit has any of the same magazines and calculate max ammo private _maxAmmo = 0; { _maxAmmo = _maxAmmo max (_x select 1); -} forEach (magazinesAmmo _player select {_x select 0 == _magazineType}); +} forEach (magazinesAmmo _unit select {(_x select 0) == _magazine}); _maxAmmo diff --git a/addons/reload/functions/fnc_onTake.sqf b/addons/reload/functions/fnc_onTake.sqf index 9f379ff643..3b5cda0873 100644 --- a/addons/reload/functions/fnc_onTake.sqf +++ b/addons/reload/functions/fnc_onTake.sqf @@ -1,6 +1,7 @@ #include "script_component.hpp" /* - * Author: ? + * Author: jokoho48 + * Called from "Take" EH. * * Arguments: * 0: Unit @@ -11,17 +12,18 @@ * None * * Example: - * [bob, backpackContainer bob, "ACE_Banana"] call ace_reload_fnc_onTake + * [player, backpackContainer player, "ACE_Banana"] call ace_reload_fnc_onTake * * Public: No */ params ["_unit", "_container", "_item"]; + if ( - _unit == ACE_player - && {GVAR(DisplayText)} - && {_item == currentMagazine _unit} - && {_container in [uniformContainer _unit, vestContainer _unit, backpackContainer _unit]} + _unit == ACE_player && + {GVAR(displayText)} && + {_item == currentMagazine _unit} && + {_container in [uniformContainer _unit, vestContainer _unit, backpackContainer _unit]} ) then { _unit call FUNC(displayAmmo); }; diff --git a/addons/reload/functions/fnc_startLinkingBelt.sqf b/addons/reload/functions/fnc_startLinkingBelt.sqf index 54fc1921d7..9dbf3cec9e 100644 --- a/addons/reload/functions/fnc_startLinkingBelt.sqf +++ b/addons/reload/functions/fnc_startLinkingBelt.sqf @@ -1,58 +1,59 @@ #include "script_component.hpp" /* - * Author: esteldunedain - * Start linking the belt + * Author: esteldunedain, johnb43 + * Start linking the belt. * * Arguments: - * 0: Player - * 1: Target + * 0: Unit executing the reload + * 1: Unit equipped with the weapon * * Return Value: * None * * Example: - * [bob, kevin] call ace_reload_fnc_startLinkingBelt + * [player, cursorTarget] call ace_reload_fnc_startLinkingBelt * * Public: No */ -params ["_player", "_target"]; +params ["_unit", "_target"]; -if (vehicle _target != _target) exitWith {false}; +if !(isNull objectParent _target) exitWith {false}; -private _magazineType = currentMagazine _target; +private _magazine = currentMagazine _target; +private _ammo = [_unit, _target] call FUNC(getAmmoToLinkBelt); - -private _maxAmmo = [_player, _target] call FUNC(getAmmoToLinkBelt); - -//if _maxAmmo is below 0 we quit -if (_maxAmmo <= 0) exitWith {}; +// If _ammo is below 0 we quit +if (_ammo <= 0) exitWith {}; // Condition to call each frame private _condition = { - (_this select 0) params ["_player", "_target"]; - ([_player, _target, []] call EFUNC(common,canInteractWith)) && ((_player distance _target) < 3) && ((speed _target) < 1) + (_this select 0) params ["_unit", "_target"]; + + ([_unit, _target, []] call EFUNC(common,canInteractWith)) && {(_unit distance _target) < 3} && {(speed _target) < 1} }; private _onFinish = { - (_this select 0) params ["_player", "_target", "_magazine"]; + (_this select 0) params ["_unit", "_target", "_magazineInfo"]; + + // Remove the magazine with given remaining ammo; If not possible, quit + if !([_unit, _magazineInfo select 0, _magazineInfo select 1] call EFUNC(common,removeSpecificMagazine)) exitWith { + [LSTRING(BeltNotLinked)] call EFUNC(common,displayTextStructured); + }; // Raise event on remote unit - [QGVAR(ammoLinked), [_target, _player, _magazine], [_target]] call CBA_fnc_targetEvent; + [QGVAR(ammoLinked), [_target, _unit, _magazineInfo], _target] call CBA_fnc_targetEvent; }; private _onFailure = { - (_this select 0) params ["_player", "_target", "_magazine"]; - [_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation); + (_this select 0) params ["_unit"]; - // Add back the magazine with the former ammo count - _player addMagazine _magazine; + [_unit, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation); + + [LSTRING(BeltNotLinked)] call EFUNC(common,displayTextStructured); }; -[_player, "PutDown"] call EFUNC(common,doGesture); - -// Remove the magazine with maximum remaining ammo -[_player, _magazineType, _maxAmmo] call EFUNC(common,removeSpecificMagazine); +[_unit, "PutDown"] call EFUNC(common,doGesture); // Call progress bar -[4, [_player, _target, [_magazineType, _maxAmmo]], _onFinish, _onFailure, (localize LSTRING(LinkingBelt)), _condition, ["isNotInside"]] call EFUNC(common,progressBar); +[4, [_unit, _target, [_magazine, _ammo]], _onFinish, _onFailure, LLSTRING(LinkingBelt), _condition, ["isNotInside"]] call EFUNC(common,progressBar); diff --git a/addons/reload/initKeybinds.sqf b/addons/reload/initKeybinds.sqf new file mode 100644 index 0000000000..cf2ae07ffb --- /dev/null +++ b/addons/reload/initKeybinds.sqf @@ -0,0 +1,16 @@ +#include "\a3\ui_f\hpp\defineDIKCodes.inc" + +// Add Keybinds +["ACE3 Weapons", QGVAR(checkAmmo), LSTRING(checkAmmo), { + // Conditions: canInteract + if !([ACE_player, vehicle ACE_player, ["isNotInside", "isNotSwimming", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {false}; + // Ignore if controlling UAV (blocks radar keybind) + if (!isNull (ACE_controlledUAV param [0, objNull])) exitWith {false}; + // Conditions: specific + if !(ACE_player call FUNC(canCheckAmmoSelf)) exitWith {false}; + + // Statement + [ACE_player, ACE_player] call FUNC(checkAmmo); + + true +}, {false}, [DIK_R, [false, true, false]], false] call CBA_fnc_addKeybind; // Ctrl + R diff --git a/addons/reload/initSettings.sqf b/addons/reload/initSettings.sqf index 23856d6668..1110ee125b 100644 --- a/addons/reload/initSettings.sqf +++ b/addons/reload/initSettings.sqf @@ -1,18 +1,15 @@ - [ QGVAR(displayText), "CHECKBOX", [LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)], - localize ELSTRING(common,ACEKeybindCategoryWeapons), - true, - 0 + ELSTRING(common,ACEKeybindCategoryWeapons), + true // default value ] call CBA_fnc_addSetting; [ QGVAR(showCheckAmmoSelf), "CHECKBOX", [LSTRING(SettingShowCheckAmmoSelf), LSTRING(SettingShowCheckAmmoSelfDesc)], - localize ELSTRING(common,ACEKeybindCategoryWeapons), - false, // default value - 0 // isGlobal + ELSTRING(common,ACEKeybindCategoryWeapons), + false // default value ] call CBA_fnc_addSetting; diff --git a/addons/reload/stringtable.xml b/addons/reload/stringtable.xml index d02599705d..a372857af9 100644 --- a/addons/reload/stringtable.xml +++ b/addons/reload/stringtable.xml @@ -129,5 +129,15 @@ 正在连接弹链... 連接彈鏈中... + + Belt was linked + Bande a été attachée + Gurt wurde angehängt + + + Belt could not be linked + Bande n'a pas pu être attachée + Gurt konnte nicht angehängt werden + diff --git a/addons/weaponselect/initSettings.sqf b/addons/weaponselect/initSettings.sqf index 507a4b5851..029c5201cb 100644 --- a/addons/weaponselect/initSettings.sqf +++ b/addons/weaponselect/initSettings.sqf @@ -1,7 +1,7 @@ [ QGVAR(displayText), "CHECKBOX", [LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)], - localize ELSTRING(common,ACEKeybindCategoryWeapons), + ELSTRING(common,ACEKeybindCategoryWeapons), true, // default value false, // isGlobal {[QGVAR(displayText), _this] call EFUNC(common,cbaSettings_settingChanged)}