diff --git a/addons/reloadlaunchers/CfgWeapons.hpp b/addons/reloadlaunchers/CfgWeapons.hpp index 268b4d84d7..75a688bf28 100644 --- a/addons/reloadlaunchers/CfgWeapons.hpp +++ b/addons/reloadlaunchers/CfgWeapons.hpp @@ -6,6 +6,9 @@ class CfgWeapons { class launch_RPG32_F: Launcher_Base_F { GVAR(enabled) = 1; }; + class launch_RPG7_F: Launcher_Base_F { + GVAR(enabled) = 1; + }; class launch_MRAWS_base_F: Launcher_Base_F { GVAR(enabled) = 1; }; diff --git a/addons/reloadlaunchers/XEH_postInit.sqf b/addons/reloadlaunchers/XEH_postInit.sqf index 2671da8e10..af5fba3bf5 100644 --- a/addons/reloadlaunchers/XEH_postInit.sqf +++ b/addons/reloadlaunchers/XEH_postInit.sqf @@ -1,4 +1,26 @@ // by commy2 #include "script_component.hpp" +[QGVAR(reloadStarted), { + params ["_unit", "_target"]; + + // Don't show notification if target is local AI + if (GVAR(displayStatusText) && {!local _unit} && {_target call EFUNC(common,isPlayer)}) then { + private _message = format [LLSTRING(LoadingStarted), _unit call EFUNC(common,getName)]; + + [_message] call EFUNC(common,displayTextStructured); + }; +}] call CBA_fnc_addEventHandler; + +[QGVAR(reloadAborted), { + params ["_unit", "_target"]; + + // Don't show notification if target is local AI + if (GVAR(displayStatusText) && {!local _unit} && {_target call EFUNC(common,isPlayer)}) then { + private _message = format [LLSTRING(LoadingAborted), _unit call EFUNC(common,getName)]; + + [_message] call EFUNC(common,displayTextStructured); + }; +}] call CBA_fnc_addEventHandler; + [QGVAR(reloadLauncher), LINKFUNC(reloadLauncher)] call CBA_fnc_addEventHandler; diff --git a/addons/reloadlaunchers/XEH_preInit.sqf b/addons/reloadlaunchers/XEH_preInit.sqf index b47cf6628d..9361d05015 100644 --- a/addons/reloadlaunchers/XEH_preInit.sqf +++ b/addons/reloadlaunchers/XEH_preInit.sqf @@ -6,4 +6,6 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +#include "initSettings.sqf" + ADDON = true; diff --git a/addons/reloadlaunchers/functions/fnc_canLoad.sqf b/addons/reloadlaunchers/functions/fnc_canLoad.sqf index 6d44680966..dc9c2769ce 100644 --- a/addons/reloadlaunchers/functions/fnc_canLoad.sqf +++ b/addons/reloadlaunchers/functions/fnc_canLoad.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* - * Author: commy2 + * Author: commy2, johnb43 * Check of the unit can reload the launcher of target unit. * * Arguments: @@ -28,6 +28,9 @@ if !(_target call EFUNC(common,isAwake)) exitWith {false}; if !(isNull objectParent _target) exitWith {false}; if !([_unit, _target, ["isNotInside", "isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false}; +// Target must not be captive +if (_target getVariable [QEGVAR(captives,isHandcuffed), false] || {_target getVariable [QEGVAR(captives,isSurrendering), false]}) exitWith {false}; + // Check if the launcher is compatible if (getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled)) == 0) exitWith {false}; diff --git a/addons/reloadlaunchers/functions/fnc_load.sqf b/addons/reloadlaunchers/functions/fnc_load.sqf index f4c851412d..6542b44c22 100644 --- a/addons/reloadlaunchers/functions/fnc_load.sqf +++ b/addons/reloadlaunchers/functions/fnc_load.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* - * Author: commy2 + * Author: commy2, johnb43, drofseh * Start reloading a launcher, reload started by the unit who has the missile. * * Arguments: @@ -26,26 +26,56 @@ private _config = configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime private _reloadTime = if (isNumber _config) then { getNumber _config } else { - 2.5 + getNumber (configFile >> "CfgWeapons" >> _weapon >> "magazineReloadTime") min 2.5 }; // Play animation [_unit] call EFUNC(common,goKneeling); +// Notify unit that is being reloaded that reload has been started +[QGVAR(reloadStarted), [_unit, _target], _target] call CBA_fnc_targetEvent; + // Show progress bar private _onSuccess = { (_this select 0) params ["_unit", "_target", "_weapon", "_magazine"]; - _unit removeMagazine _magazine; + // 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 _unit select {(_x select 0) == _magazine}); + + // Check if the launcher can still be loaded; If possible, then try to remove magazine + if !(_maxAmmo > 0 && {[_unit, _target, _weapon, _magazine] call FUNC(canLoad)} && {[_unit, _magazine, _maxAmmo] call EFUNC(common,removeSpecificMagazine)}) exitWith { + // Notify unit that was being reloaded that reload has been stopped + [QGVAR(reloadAborted), [_unit, _target], _target] call CBA_fnc_targetEvent; + + // Notify reloading unit about failure + if (GVAR(displayStatusText)) then { + [LSTRING(LauncherNotLoaded)] call EFUNC(common,displayTextStructured); + }; + }; // Reload target's launcher - [QGVAR(reloadLauncher), [_unit, _target, _weapon, _magazine], _target] call CBA_fnc_targetEvent; + [QGVAR(reloadLauncher), [_unit, _target, _weapon, _magazine, _maxAmmo], _target] call CBA_fnc_targetEvent; - [LLSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured); + // Notify reloading unit about success + if (GVAR(displayStatusText)) then { + [LSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured); + }; }; private _onFailure = { - [LELSTRING(common,ActionAborted)] call EFUNC(common,displayTextStructured); + (_this select 0) params ["_unit", "_target"]; + + // Notify unit that was being reloaded that reload has been stopped + [QGVAR(reloadAborted), [_unit, _target], _target] call CBA_fnc_targetEvent; + + // Notify reloading unit about failure + if (GVAR(displayStatusText)) then { + [LSTRING(LauncherNotLoaded)] call EFUNC(common,displayTextStructured); + }; }; private _condition = { diff --git a/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf b/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf index a371406dc3..b159ae8ece 100644 --- a/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf +++ b/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf @@ -1,13 +1,15 @@ #include "script_component.hpp" /* - * Author: commy2 + * Author: commy2, johnb43, drofseh * Reload a launcher for the unit who has the launcher. + * If the ammo argument is nil, a full magazine will be given. * * Arguments: - * 0: Unit executing the reload - * 1: Unit equipped with the launcher - * 2: Launcher name - * 3: Missile name + * 0: Unit to do the reloading + * 1: Target to rload + * 2: weapon name + * 3: missile name + * 4: Ammo count * * Return Value: * None @@ -18,12 +20,13 @@ * Public: No */ -params ["_unit", "_target", "_weapon", "_magazine"]; -TRACE_4("params",_unit,_target,_weapon,_magazine); +params ["_unit", "_target", "_weapon", "_magazine", "_ammo"]; +TRACE_5("params",_unit,_target,_weapon,_magazine,_ammo); -_target selectWeapon _weapon; +// Add magazine to launcher immediately +_target addWeaponItem [_weapon, [_magazine, _ammo], true]; -if (currentWeapon _target != _weapon) exitWith {}; -if (currentMagazine _target != "") exitWith {}; - -_target addWeaponItem [_weapon, _magazine, true]; +// Don't show notification if target is local AI +if (GVAR(displayStatusText) && {!local _unit} && {_target call EFUNC(common,isPlayer)}) then { + [LSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured); +}; diff --git a/addons/reloadlaunchers/initSettings.sqf b/addons/reloadlaunchers/initSettings.sqf new file mode 100644 index 0000000000..687a74ef37 --- /dev/null +++ b/addons/reloadlaunchers/initSettings.sqf @@ -0,0 +1,8 @@ +[ + QGVAR(displayStatusText), + "CHECKBOX", + [LSTRING(SettingDisplayStatusTextName), LSTRING(SettingDisplayStatusTextDesc)], + ELSTRING(common,ACEKeybindCategoryWeapons), + true, + 2 +] call CBA_fnc_addSetting; diff --git a/addons/reloadlaunchers/stringtable.xml b/addons/reloadlaunchers/stringtable.xml index 75653f6add..64070bdae3 100644 --- a/addons/reloadlaunchers/stringtable.xml +++ b/addons/reloadlaunchers/stringtable.xml @@ -1,6 +1,12 @@ + + Display notifications for buddy loading + + + Displays notifications when an assistant loads a gunner's launcher. + Load launcher Panzerabwehr laden @@ -18,6 +24,16 @@ 裝載發射器 Fırlatıcıyı Yükle + + %1 is loading your launcher + %1 lädt deine Panzerabwehr + %1 charge ton lanceur + + + %1 stopped loading your launcher + %1 hat aufgehört, deine Panzerabwehr zu laden + %1 a arrêté de charger ton lanceur + Loading launcher... Chargement du lanceur... @@ -69,5 +85,10 @@ 裝載%1 %1 Yüklendi + + Launcher could not be loaded + Panzerabwehr konnte nicht geladen werden + Lanceur n'a pas pu être chargé +