Reload - Code cleanup and various improvements (#9343)

* Reload code cleanup

* Update fnc_startLinkingBelt.sqf

* Update addons/reload/functions/fnc_getAmmoToLinkBelt.sqf

Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com>

---------

Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com>
This commit is contained in:
johnb432 2023-08-28 19:26:24 +02:00 committed by GitHub
parent 519b1cbeb4
commit 44e0fdb6fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 188 additions and 168 deletions

View File

@ -68,7 +68,7 @@ private _categoryColors = [_category, format ["| %1 |", LLSTRING(subcategory_col
QGVAR(persistentLaserEnabled), QGVAR(persistentLaserEnabled),
"CHECKBOX", "CHECKBOX",
[LSTRING(SettingPersistentLaserName), LSTRING(SettingPersistentLaserDesc)], [LSTRING(SettingPersistentLaserName), LSTRING(SettingPersistentLaserDesc)],
localize LSTRING(ACEKeybindCategoryWeapons), LSTRING(ACEKeybindCategoryWeapons),
false, false,
false, false,
LINKFUNC(switchPersistentLaser) LINKFUNC(switchPersistentLaser)

View File

@ -1,7 +1,7 @@
[ [
QGVAR(enabled), "CHECKBOX", QGVAR(enabled), "CHECKBOX",
LSTRING(DisplayName), LSTRING(DisplayName),
localize ELSTRING(common,ACEKeybindCategoryWeapons), ELSTRING(common,ACEKeybindCategoryWeapons),
true, true,
1 1
] call CBA_fnc_addSetting; ] call CBA_fnc_addSetting;

View File

@ -1,4 +1,3 @@
class Extended_PreStart_EventHandlers { class Extended_PreStart_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));

View File

@ -14,16 +14,16 @@ class CfgVehicles {
class ACE_Actions { class ACE_Actions {
class ACE_Weapon { class ACE_Weapon {
class GVAR(LinkBelt) { class GVAR(linkBelt) {
displayName = CSTRING(LinkBelt); displayName = CSTRING(linkBelt);
distance = 2.0; distance = 2;
condition = QUOTE(([ARR_2(_player, _target)] call FUNC(getAmmoToLinkBelt)) > 0); condition = QUOTE(([ARR_2(_player, _target)] call FUNC(getAmmoToLinkBelt)) > 0);
statement = QUOTE([ARR_2(_player, _target)] call FUNC(startLinkingBelt)); statement = QUOTE([ARR_2(_player, _target)] call FUNC(startLinkingBelt));
exceptions[] = {"isNotInside"}; exceptions[] = {"isNotInside"};
}; };
class GVAR(CheckAmmo) { class GVAR(checkAmmo) {
displayName = CSTRING(checkAmmo); displayName = CSTRING(checkAmmo);
distance = 2.0; distance = 2;
condition = QUOTE(call FUNC(canCheckAmmo)); condition = QUOTE(call FUNC(canCheckAmmo));
statement = QUOTE(call FUNC(checkAmmo)); statement = QUOTE(call FUNC(checkAmmo));
exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"}; exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"};
@ -36,9 +36,9 @@ class CfgVehicles {
class StaticWeapon: LandVehicle { class StaticWeapon: LandVehicle {
class ACE_Actions { class ACE_Actions {
class ACE_MainActions { class ACE_MainActions {
class GVAR(CheckAmmo) { class GVAR(checkAmmo) {
displayName = CSTRING(checkAmmo); displayName = CSTRING(checkAmmo);
distance = 2.0; distance = 2;
condition = QUOTE(call FUNC(canCheckAmmo)); condition = QUOTE(call FUNC(canCheckAmmo));
statement = QUOTE(call FUNC(checkAmmo)); statement = QUOTE(call FUNC(checkAmmo));
exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"}; exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"};

View File

@ -1,4 +1,3 @@
PREP(canCheckAmmo); PREP(canCheckAmmo);
PREP(canCheckAmmoSelf); PREP(canCheckAmmoSelf);
PREP(getAmmoToLinkBelt); PREP(getAmmoToLinkBelt);

View File

@ -1,63 +1,55 @@
// by esteldunedain // by esteldunedain
#include "script_component.hpp" #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;
[QGVAR(syncAmmo), {
// To propagate the setAmmo change, do it on all clients // 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), {
params ["_unit", "_weapon", "_ammo"]; params ["_unit", "_weapon", "_ammo"];
TRACE_3("syncAmmo EH",_unit,_weapon,_ammo); TRACE_3("syncAmmo EH",_unit,_weapon,_ammo);
_unit setAmmo [_weapon, _ammo]; _unit setAmmo [_weapon, _ammo];
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
// Listen for attempts to link ammo // Listen for attempts to link ammo
[QGVAR(ammoLinked), { [QGVAR(ammoLinked), {
params ["_receiver", "_giver", "_magazine"]; params ["_target", "_unit", "_magazineInfo"];
_magazineInfo params ["_magazine", "_ammo"];
private _magazineType = currentMagazine _receiver;
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
// Return the magazine if it's the wrong type // Return the magazine if it's the wrong type
if (_magazineType != (_magazine select 0)) exitWith { if (currentMagazine _target != _magazine) exitWith {
[QGVAR(ammoReturned), [_giver,_receiver,_magazine], [_giver]] call CBA_fnc_targetEvent; [QGVAR(ammoReturned), [_unit, _target, _magazineInfo, false], _unit] call CBA_fnc_targetEvent;
}; };
private _ammoCount = _receiver ammo currentWeapon _receiver; private _currentWeapon = currentWeapon _target;
private _ammoMissing = getNumber (_magazineCfg >> "count") - _ammoCount; 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 // Return the magazine if the belt is full or empty
if ((_ammoCount == 0) || _ammoMissing == 0) exitWith { if (_currentAmmo == 0 || {_ammoMissing == 0}) exitWith {
[QGVAR(ammoReturned), [_giver,_receiver,_magazine], [_giver]] call CBA_fnc_targetEvent; [QGVAR(ammoReturned), [_unit, _target, _magazineInfo, false], _unit] call CBA_fnc_targetEvent;
}; };
// Add the ammo // Add the ammo
private _ammoAdded = _ammoMissing min (_magazine select 1); private _ammoAdded = _ammoMissing min _ammo;
[QGVAR(syncAmmo), [_receiver, currentWeapon _receiver, _ammoCount + _ammoAdded]] call CBA_fnc_globalEvent; [QGVAR(syncAmmo), [_target, _currentWeapon, _currentAmmo + _ammoAdded]] call CBA_fnc_globalEvent;
if ((_magazine select 1) - _ammoAdded > 0) then { // Return left over ammo to reloading unit
[QGVAR(ammoReturned), [_giver, _receiver, [_magazineType, (_magazine select 1) - _ammoAdded]], [_giver]] call CBA_fnc_targetEvent; if (_ammo - _ammoAdded > 0) then {
[QGVAR(ammoReturned), [_unit, _target, [_magazine, _ammo - _ammoAdded], true], _unit] call CBA_fnc_targetEvent;
}; };
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
// Listen for returned magazines // Listen for returned magazines
[QGVAR(ammoReturned), { [QGVAR(ammoReturned), {
params ["_receiver", "", "_magazine"]; params ["_unit", "_target", "_magazineInfo", "_success"];
TRACE_2("ammoReturned EH",_receiver,_magazine); 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; }] call CBA_fnc_addEventHandler;
if (!hasInterface) exitWith {};
#include "initKeybinds.sqf"

View File

@ -1,13 +1,13 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: CAA-Picard * Author: CAA-Picard, johnb43
* Check if the player can check the ammo of the target. * Check if a unit can check the ammo of the target.
* *
* Arguments: * Arguments:
* 0: Target <OBJECT> * 0: Unit equipped with the weapon <OBJECT>
* *
* Return Value: * Return Value:
* Can link belt<BOOL> * Can check ammo <BOOL>
* *
* Example: * Example:
* [cursorObject] call ace_reload_fnc_canCheckAmmo * [cursorObject] call ace_reload_fnc_canCheckAmmo
@ -17,26 +17,18 @@
params ["_target"]; 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 (_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}; if (!alive _target) exitWith {false};
private _found = false; if (currentMagazine _target != "") exitWith {true};
{ // Check for loaded magazines
if (_x select 2) exitWith { (magazinesAmmoFull _target) findIf {_x select 2} != -1
_found = true;
};
false
} count magazinesAmmoFull _target;
_found
}; };
// Return false for all other vehicles // All other vehicles
if !(_target isKindOf "CAManBase") exitWith {false}; if !(_target isKindOf "CAManBase") exitWith {false};
// For men // For men

View File

@ -7,10 +7,10 @@
* 0: Player <OBJECT> * 0: Player <OBJECT>
* *
* Return Value: * Return Value:
* Can check ammo <BOOL> * Can check ammo for self <BOOL>
* *
* Example: * Example:
* [cursorObject] call ace_reload_fnc_canCheckAmmoSelf * [player] call ace_reload_fnc_canCheckAmmoSelf
* *
* Public: No * Public: No
*/ */

View File

@ -1,11 +1,11 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: commy2 and esteldunedain * Author: commy2, esteldunedain
* Count the ammo of the currently loaded magazine or count rifle grenades. Play animation and display message. * Play animation and display message.
* *
* Arguments: * Arguments:
* 0: Target. <OBJECT> * 0: Unit equipped with the weapon <OBJECT>
* 1: Player <OBJECT> * 1: Unit to execute the reload <OBJECT>
* *
* Return Value: * Return Value:
* None * None
@ -16,13 +16,14 @@
* Public: No * Public: No
*/ */
params ["_target", "_player"]; params ["_target", "_unit"];
if (_player == _target) then { if (_unit == _target) then {
if ((vehicle _target) isKindOf "StaticWeapon") then { if ((vehicle _target) isKindOf "StaticWeapon") then {
_target = vehicle _target; _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;

View File

@ -1,16 +1,16 @@
#include "script_component.hpp" #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. * Display the ammo of the currently loaded magazine of the target or count rifle grenades.
* *
* Arguments: * Arguments:
* 0: Target <OBJECT> * 0: Unit equipped with the weapon <OBJECT>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* player call ace_reload_fnc_displayAmmo * [player] call ace_reload_fnc_displayAmmo
* *
* Public: No * Public: No
*/ */
@ -21,59 +21,58 @@ params ["_target"];
private _isStaticWeapon = _target isKindOf "StaticWeapon"; private _isStaticWeapon = _target isKindOf "StaticWeapon";
if (_isStaticWeapon) then { // currentWeapon, currentMagazine and weaponState return "" for static weapons before they have been entered once
[currentWeapon _target, currentMuzzle _target, "", currentMagazine _target] (if (_isStaticWeapon) then {
} else { private _weapon = currentWeapon _target;
weaponState _target
} params ["_weapon", "_muzzle", "", "_magazine"];
// currentWeapon returns "" for static weapons before they are shot once
if (_isStaticWeapon) then {
if (_weapon == "") then { if (_weapon == "") then {
if (count (weapons _target) == 1) then { private _weapons = weapons _target;
_weapon = (weapons _target) select 0;
_muzzle = _weapon; if (count _weapons == 1) then {
_weapon = _weapons select 0;
}; };
}; };
private _magazine = currentMagazine _target;
if (_magazine == "") then { if (_magazine == "") then {
// Try to get magazine using magazinesAmmoFull // Try to get magazine using magazinesAmmoFull
private _magazines = magazinesAmmoFull _target;
{ {
if (_x select 2) exitWith { if (_x select 2) exitWith {
_magazine = _x select 0; _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 // currentMuzzle always returns ""
if (_muzzle == "") then { [_weapon, _weapon, "", _magazine]
_muzzle = _weapon; } else {
}; weaponState _target
}; }) params ["_weapon", "_muzzle", "", "_magazine"];
TRACE_3("",_weapon,_muzzle,_magazine); TRACE_3("",_weapon,_muzzle,_magazine);
if ("" in [_weapon, _magazine]) exitWith {}; if ("" == _weapon) exitWith {};
private _ammo = _target ammo _muzzle; private _ammo = _target ammo _muzzle;
private _magazineConfig = configFile >> "CfgMagazines" >> _magazine; private _magazineCfg = configFile >> "CfgMagazines" >> _magazine;
private _maxRounds = getNumber (_magazineConfig >> "count") max 1; private _maxRounds = getNumber (_magazineCfg >> "count") max 1;
private _count = -1; // Show a count instead of ammo bars (ignore if -1) private _count = -1; // Show a count instead of ammo bars (ignore if -1)
if (_muzzle != _weapon) then { // If secondary muzzle is selected or no magazine in current muzzle
// grenade launcher (or some kind of seconday muzzle) if (_muzzle != _weapon || {_magazine == ""}) then {
if (_ammo > 0) then { // Check if no or empty magazine; If true, just show count of compatible magazines
if (_maxRounds == 1) then { // singleShot so show count of identical mags available instead of ammo bars if (_ammo == 0) exitWith {
_count = 1 + ({_x == _magazine} count magazines _target); _magazine = ""; // Make sure, as it could also be secondary muzzle being selected
};
} else { private _compatibleMagazines = compatibleMagazines [_weapon, _muzzle];
if (_maxRounds <= 3) then { // empty GL/3GL - don't have a real magazine so just show count of any compatible mag
_magazine = ""; _count = {_x in _compatibleMagazines} count (magazines _target);
private _compatibleMagazines = [configFile >> "CfgWeapons" >> _weapon >> _muzzle] call CBA_fnc_compatibleMagazines;
_count = {_x in _compatibleMagazines} count (magazines _target); // safe because everything is config case
}; };
// 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 { if (_maxRounds >= COUNT_BARS) then {
_count = round (COUNT_BARS * _ammo / _maxRounds); _count = round (COUNT_BARS * _ammo / _maxRounds);
if (_ammo > 0) then {_count = _count max 1}; if (_ammo > 0) then {
if (_ammo < _maxRounds) then {_count = _count min (COUNT_BARS - 1)}; _count = _count max 1;
};
if (_ammo < _maxRounds) then {
_count = _count min (COUNT_BARS - 1);
};
} else { } else {
_count = _ammo; _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 = ""; private _string = "";
for "_a" from 1 to _count do { for "_a" from 1 to _count do {
_string = _string + "|"; _string = _string + "|";
}; };
private _text = [_string, _color] call EFUNC(common,stringToColoredText); private _text = [_string, _color] call EFUNC(common,stringToColoredText);
_string = ""; _string = "";
for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do { for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do {
_string = _string + "|"; _string = _string + "|";
}; };
@ -105,16 +112,21 @@ private _ammoBarsStructuredText = if (_count >= 0) then {
composeText [_text, [_string, "#808080"] call EFUNC(common,stringToColoredText)]; composeText [_text, [_string, "#808080"] call EFUNC(common,stringToColoredText)];
}; };
if (_isStaticWeapon) then { if (_isStaticWeapon) then {
//Vehicle mags (usualy) don't have pictures, so just show the text above ammo count // Vehicle mags usually don't have pictures, so just show the text above ammo count
private _loadedName = getText (_magazineConfig >> "displaynameshort"); private _loadedName = getText (_magazineCfg >> "displayNameShort");
if (_loadedName == "") then {
_loadedName = getText (_magazineCfg >> "displayName");
};
_loadedName = parseText format ["<t align='center' >%1</t>", _loadedName]; _loadedName = parseText format ["<t align='center' >%1</t>", _loadedName];
private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText]; private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText];
[_text] call EFUNC(common,displayTextStructured); [_text] call EFUNC(common,displayTextStructured);
} else { } else {
if (_magazine != "") then { if (_magazine != "") then {
private _picture = getText (_magazineConfig >> "picture"); private _picture = getText (_magazineCfg >> "picture");
[_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture); [_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture);
} else { } else {
[_ammoBarsStructuredText, 1] call EFUNC(common,displayTextStructured); [_ammoBarsStructuredText, 1] call EFUNC(common,displayTextStructured);

View File

@ -1,11 +1,11 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: esteldunedain, phyma * 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: * Arguments:
* 0: Player <OBJECT> * 0: Unit wanting to execute the reload <OBJECT>
* 1: Target <OBJECT> * 1: Unit equipped with the weapon <OBJECT>
* *
* Return Value: * Return Value:
* Maximum ammo of magazine (-1 on error) <NUMBER> * Maximum ammo of magazine (-1 on error) <NUMBER>
@ -16,12 +16,12 @@
* Public: No * 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 _magazine = currentMagazine _target;
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType; private _magazineCfg = configFile >> "CfgMagazines" >> _magazine;
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {-1}; 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; private _ammoCount = _target ammo currentWeapon _target;
// Exit if the belt is full or empty // 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 // Check if the unit has any of the same magazines and calculate max ammo
// Calculate max ammo
private _maxAmmo = 0; private _maxAmmo = 0;
{ {
_maxAmmo = _maxAmmo max (_x select 1); _maxAmmo = _maxAmmo max (_x select 1);
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType}); } forEach (magazinesAmmo _unit select {(_x select 0) == _magazine});
_maxAmmo _maxAmmo

View File

@ -1,6 +1,7 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: ? * Author: jokoho48
* Called from "Take" EH.
* *
* Arguments: * Arguments:
* 0: Unit <OBJECT> * 0: Unit <OBJECT>
@ -11,17 +12,18 @@
* None * None
* *
* Example: * Example:
* [bob, backpackContainer bob, "ACE_Banana"] call ace_reload_fnc_onTake * [player, backpackContainer player, "ACE_Banana"] call ace_reload_fnc_onTake
* *
* Public: No * Public: No
*/ */
params ["_unit", "_container", "_item"]; params ["_unit", "_container", "_item"];
if ( if (
_unit == ACE_player _unit == ACE_player &&
&& {GVAR(DisplayText)} {GVAR(displayText)} &&
&& {_item == currentMagazine _unit} {_item == currentMagazine _unit} &&
&& {_container in [uniformContainer _unit, vestContainer _unit, backpackContainer _unit]} {_container in [uniformContainer _unit, vestContainer _unit, backpackContainer _unit]}
) then { ) then {
_unit call FUNC(displayAmmo); _unit call FUNC(displayAmmo);
}; };

View File

@ -1,58 +1,59 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: esteldunedain * Author: esteldunedain, johnb43
* Start linking the belt * Start linking the belt.
* *
* Arguments: * Arguments:
* 0: Player <OBJECT> * 0: Unit executing the reload <OBJECT>
* 1: Target <OBJECT> * 1: Unit equipped with the weapon <OBJECT>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [bob, kevin] call ace_reload_fnc_startLinkingBelt * [player, cursorTarget] call ace_reload_fnc_startLinkingBelt
* *
* Public: No * 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);
// If _ammo is below 0 we quit
private _maxAmmo = [_player, _target] call FUNC(getAmmoToLinkBelt); if (_ammo <= 0) exitWith {};
//if _maxAmmo is below 0 we quit
if (_maxAmmo <= 0) exitWith {};
// Condition to call each frame // Condition to call each frame
private _condition = { private _condition = {
(_this select 0) params ["_player", "_target"]; (_this select 0) params ["_unit", "_target"];
([_player, _target, []] call EFUNC(common,canInteractWith)) && ((_player distance _target) < 3) && ((speed _target) < 1)
([_unit, _target, []] call EFUNC(common,canInteractWith)) && {(_unit distance _target) < 3} && {(speed _target) < 1}
}; };
private _onFinish = { 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 // 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 = { private _onFailure = {
(_this select 0) params ["_player", "_target", "_magazine"]; (_this select 0) params ["_unit"];
[_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);
// Add back the magazine with the former ammo count [_unit, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);
_player addMagazine _magazine;
[LSTRING(BeltNotLinked)] call EFUNC(common,displayTextStructured);
}; };
[_player, "PutDown"] call EFUNC(common,doGesture); [_unit, "PutDown"] call EFUNC(common,doGesture);
// Remove the magazine with maximum remaining ammo
[_player, _magazineType, _maxAmmo] call EFUNC(common,removeSpecificMagazine);
// Call progress bar // 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);

View File

@ -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

View File

@ -1,18 +1,15 @@
[ [
QGVAR(displayText), QGVAR(displayText),
"CHECKBOX", "CHECKBOX",
[LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)], [LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)],
localize ELSTRING(common,ACEKeybindCategoryWeapons), ELSTRING(common,ACEKeybindCategoryWeapons),
true, true // default value
0
] call CBA_fnc_addSetting; ] call CBA_fnc_addSetting;
[ [
QGVAR(showCheckAmmoSelf), QGVAR(showCheckAmmoSelf),
"CHECKBOX", "CHECKBOX",
[LSTRING(SettingShowCheckAmmoSelf), LSTRING(SettingShowCheckAmmoSelfDesc)], [LSTRING(SettingShowCheckAmmoSelf), LSTRING(SettingShowCheckAmmoSelfDesc)],
localize ELSTRING(common,ACEKeybindCategoryWeapons), ELSTRING(common,ACEKeybindCategoryWeapons),
false, // default value false // default value
0 // isGlobal
] call CBA_fnc_addSetting; ] call CBA_fnc_addSetting;

View File

@ -129,5 +129,15 @@
<Chinesesimp>正在连接弹链...</Chinesesimp> <Chinesesimp>正在连接弹链...</Chinesesimp>
<Chinese>連接彈鏈中...</Chinese> <Chinese>連接彈鏈中...</Chinese>
</Key> </Key>
<Key ID="STR_ACE_Reload_BeltLinked">
<English>Belt was linked</English>
<French>Bande a été attachée</French>
<German>Gurt wurde angehängt</German>
</Key>
<Key ID="STR_ACE_Reload_BeltNotLinked">
<English>Belt could not be linked</English>
<French>Bande n'a pas pu être attachée</French>
<German>Gurt konnte nicht angehängt werden</German>
</Key>
</Package> </Package>
</Project> </Project>

View File

@ -1,7 +1,7 @@
[ [
QGVAR(displayText), "CHECKBOX", QGVAR(displayText), "CHECKBOX",
[LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)], [LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)],
localize ELSTRING(common,ACEKeybindCategoryWeapons), ELSTRING(common,ACEKeybindCategoryWeapons),
true, // default value true, // default value
false, // isGlobal false, // isGlobal
{[QGVAR(displayText), _this] call EFUNC(common,cbaSettings_settingChanged)} {[QGVAR(displayText), _this] call EFUNC(common,cbaSettings_settingChanged)}