mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Keep empty magazines when reloading
This commit is contained in:
parent
02794a972b
commit
3e1e4fca27
@ -13,14 +13,12 @@ class Extended_PreInit_EventHandlers {
|
||||
|
||||
class Extended_PostInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE( call COMPILE_FILE(XEH_postInit) );
|
||||
init = QUOTE(call COMPILE_FILE(XEH_postInit));
|
||||
};
|
||||
};
|
||||
|
||||
class Extended_Take_EventHandlers {
|
||||
class Extended_Reloaded_EventHandlers {
|
||||
class CAManBase {
|
||||
class ACE_AmmoIndicatorReload {
|
||||
clientTake = QUOTE(if (_this select 0 == ACE_player && {GVAR(DisplayText)} && {(_this select 1) in [ARR_3(uniformContainer (_this select 0), vestContainer (_this select 0), backpackContainer (_this select 0))]} && {_this select 2 == currentMagazine (_this select 0)}) then {[ARR_2(_this select 0, vehicle (_this select 0))] call FUNC(displayAmmo)};);
|
||||
};
|
||||
ADDON = QUOTE(call FUNC(onReload));
|
||||
};
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
PREP(canCheckAmmo);
|
||||
PREP(canLinkBelt);
|
||||
PREP(checkAmmo);
|
||||
PREP(displayAmmo);
|
||||
PREP(onInventoryChanged);
|
||||
PREP(onReload);
|
||||
PREP(startLinkingBelt);
|
||||
|
@ -59,3 +59,5 @@ if (!hasInterface) exitWith {};
|
||||
|
||||
_receiver addMagazine _magazine;
|
||||
}] call CBA_fnc_addEventHandler;
|
||||
|
||||
["loadout", {call FUNC(onInventoryChanged)}] call CBA_fnc_addPlayerEventHandler;
|
||||
|
47
addons/reload/functions/fnc_onInventoryChanged.sqf
Normal file
47
addons/reload/functions/fnc_onInventoryChanged.sqf
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Author: BaerMitUmlaut
|
||||
* Handles unit weight coefficient for empty magazines.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: Previous loadout <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
params ["_unit", "_previousLoadout"];
|
||||
|
||||
private _loadout = getUnitLoadout _unit;
|
||||
_loadout params ["", "", "", "_uniformInventory", "_vestInventory", "_backpackInventory"];
|
||||
|
||||
private _prevEmptyMagsWeight = _unit getVariable [QGVAR(emptyMagazinesWeight), 0];
|
||||
private _emptyMagsWeight = 0;
|
||||
|
||||
if (isNil QGVAR(magWeightCache)) then {
|
||||
GVAR(magWeightCache) = [] call CBA_fnc_createNamespace;
|
||||
};
|
||||
|
||||
{
|
||||
if !(_x isEqualTo []) then {
|
||||
private _mags = _x select 1;
|
||||
{
|
||||
_x params ["_classname", "_ammoCount", "_magCount"];
|
||||
|
||||
if (_ammoCount == 0) then {
|
||||
private _weight = GVAR(magWeightCache) getVariable _classname;
|
||||
if (isNil "_weight") then {
|
||||
_weight = getNumber (configFile >> "CfgMagazines" >> _classname >> "mass");
|
||||
GVAR(magWeightCache) setVariable [_classname, _weight];
|
||||
systemChat "nocache";
|
||||
};
|
||||
_emptyMagsWeight = _emptyMagsWeight + _weight * _magCount;
|
||||
};
|
||||
} forEach _mags;
|
||||
};
|
||||
} forEach [_uniformInventory, _vestInventory, _backpackInventory];
|
||||
|
||||
if (_emptyMagsWeight != _prevEmptyMagsWeight) then {
|
||||
_unit setVariable [QGVAR(emptyMagazinesWeight), _emptyMagsWeight];
|
||||
[_unit, _unit, -0.8 * (_emptyMagsWeight - _prevEmptyMagsWeight)] call EFUNC(movement,addLoadToUnitContainer);
|
||||
};
|
27
addons/reload/functions/fnc_onReload.sqf
Normal file
27
addons/reload/functions/fnc_onReload.sqf
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Author: BaerMitUmlaut
|
||||
* Handles the ammo display on reload and and adds empty magazines.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: Weapon <STRING>
|
||||
* 2: Muzzle <STRING>
|
||||
* 3: New magazine info <ARRAY>
|
||||
* 4: Old magazine info <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
params ["_unit", "_weapon", "_muzzle", "_newMagInfo", ["_oldMagInfo", ["", -1]]];
|
||||
_oldMagInfo params ["_oldMagClassname", "_oldMagAmmo"];
|
||||
|
||||
if (_unit == ACE_player) then {
|
||||
if (GVAR(DisplayText)) then {
|
||||
[_unit] call FUNC(displayAmmo);
|
||||
};
|
||||
|
||||
if (_oldMagAmmo == 0 && {_unit canAdd _oldMagClassname} && {_weapon != secondaryWeapon _unit}) then {
|
||||
_unit addMagazine [_oldMagClassname, 0];
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user