Reload - Fix display ammo count in vehicle (#7730)

* Fix display ammo count in vehicle

* Revert CSW changes
This commit is contained in:
Dystopian 2020-06-14 00:54:06 +04:00 committed by GitHub
parent 79ca6f5141
commit 2eedf7a4e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 20 deletions

View File

@ -20,7 +20,15 @@ class Extended_PostInit_EventHandlers {
class Extended_Take_EventHandlers {
class CAManBase {
class ACE_AmmoIndicatorReload {
clientTake = QUOTE(params ['_unit']; if (_unit == ACE_player && {GVAR(DisplayText)} && {(_this select 1) in [ARR_3(uniformContainer _unit, vestContainer _unit, backpackContainer _unit)]} && {_this select 2 == currentMagazine _unit}) then {[ARR_2(_unit, vehicle _unit)] call FUNC(displayAmmo)};);
clientTake = QUOTE( \
params [ARR_3('_unit', '_container', '_item')]; \
if ( \
_unit == ACE_player \
&& {GVAR(DisplayText)} \
&& {_container in [ARR_3(uniformContainer _unit, vestContainer _unit, backpackContainer _unit)]} \
&& {_item == currentMagazine _unit} \
) then {_unit call DFUNC(displayAmmo)}; \
);
};
};
};

View File

@ -10,7 +10,7 @@
* None
*
* Example:
* [bob] call ace_reload_fnc_displayAmmo
* player call ace_reload_fnc_displayAmmo
*
* Public: No
*/
@ -19,12 +19,16 @@
params ["_target"];
private _weapon = currentWeapon _target;
private _muzzle = currentMuzzle _target;
private _magazine = currentMagazine _target;
private _isStaticWeapon = _target isKindOf "StaticWeapon";
if (_isStaticWeapon) then {
[currentWeapon _target, currentMuzzle _target, "", currentMagazine _target]
} else {
weaponState _target
} params ["_weapon", "_muzzle", "", "_magazine"];
// currentWeapon returns "" for static weapons before they are shot once
if (_target isKindOf "StaticWeapon") then {
if (_isStaticWeapon) then {
if (_weapon == "") then {
if (count (weapons _target) == 1) then {
_weapon = (weapons _target) select 0;
@ -49,23 +53,20 @@ if (_target isKindOf "StaticWeapon") then {
};
};
if (_magazine == "") exitWith {};
if (_weapon == "") exitWith {};
if (!( _muzzle isEqualType "")) then {_muzzle = _weapon};
TRACE_3("",_weapon,_muzzle,_magazine);
private _ammo = 0;
private _maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count") max 1;
if ("" in [_weapon, _magazine]) exitWith {};
private _ammo = _target ammo _muzzle;
private _magazineConfig = configFile >> "CfgMagazines" >> _magazine;
private _maxRounds = getNumber (_magazineConfig >> "count") max 1;
private _count = -1; // Show a count instead of ammo bars (ignore if -1)
// not grenade launcher
if (_muzzle == _weapon) then {
_ammo = _target ammo _weapon;
} else {
if (_muzzle != _weapon) then {
// grenade launcher (or some kind of seconday muzzle)
_ammo = _target ammo _muzzle;
if (_ammo > 0) then {
if (_maxRounds == 1) then { // singleShot so show count of identical mags available instead of ammo bars
_count = {_x == _magazine} count (magazines _target + [_magazine]) // add the loaded mag
_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
@ -105,15 +106,15 @@ private _ammoBarsStructuredText = if (_count >= 0) then {
};
if (_target isKindOf "StaticWeapon") then {
if (_isStaticWeapon) then {
//Vehicle mags (usualy) don't have pictures, so just show the text above ammo count
private _loadedName = getText (configFile >> "CfgMagazines" >> _magazine >> "displaynameshort");
private _loadedName = getText (_magazineConfig >> "displaynameshort");
_loadedName = parseText format ["<t align='center' >%1</t>", _loadedName];
private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText];
[_text] call EFUNC(common,displayTextStructured);
} else {
if (_magazine != "") then {
private _picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture");
private _picture = getText (_magazineConfig >> "picture");
[_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture);
} else {
[_ammoBarsStructuredText, 1] call EFUNC(common,displayTextStructured);