Pylons - Fix old weapons not being removed (#6100)

* Pylons - Fix old weapons not being removed

Fix  #6088
- Use removeWeaponTurret instead of removeWeaponGlobal
- Fix "Too Far" warning showing on completion

* Fix _x

* Fix var name

Co-Authored-By: Ozan Eğitmen <ozanegitmen@gmail.com>
This commit is contained in:
PabstMirror 2018-02-09 19:17:57 -06:00 committed by GitHub
parent 59783a2e7a
commit 4cabaa48b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -28,8 +28,17 @@
} forEach GVAR(aircraftWithPylons);
[QGVAR(setPylonLoadOutEvent), {
params ["_aircraft", "_pylonIndex", "_pylon", "_turret"];
params ["_aircraft", "_pylonIndex", "_pylon", "_turret", "_weaponToRemove"];
TRACE_5("setPylonLoadOutEvent",_aircraft,_pylonIndex,_pylon,_turret,_weaponToRemove);
_aircraft setPylonLoadOut [_pylonIndex, _pylon, false, _turret];
if (_weaponToRemove != "") then {
{
if (_aircraft turretLocal _x) then {
TRACE_3("removing",_aircraft,_x,_weaponToRemove);
_aircraft removeWeaponTurret [_weaponToRemove, _x];
};
} forEach [[-1], [0]];
};
}] call CBA_fnc_addEventHandler;
[QGVAR(setAmmoOnPylonEvent), {

View File

@ -27,8 +27,10 @@ if (_currentPylon == count _pylonsToConfigure) exitWith {};
{
(_this select 0) params ["_pylonsToConfigure", "_currentPylon"];
private _pylonIndex = _pylonsToConfigure select _currentPylon;
TRACE_2("",_currentPylon,_pylonIndex);
// Remove the weapon of current pylon from aircraft IF weapon is only on this pylon
private _weaponToRemove = "";
private _currentPylonMagazine = (getPylonMagazines GVAR(currentAircraft)) select _pylonIndex;
if (_currentPylonMagazine != "") then {
private _allPylonWeapons = (getPylonMagazines GVAR(currentAircraft)) apply {
@ -36,7 +38,8 @@ if (_currentPylon == count _pylonsToConfigure) exitWith {};
};
private _pylonWeapon = _allPylonWeapons select _pylonIndex;
if (({_x == _pylonWeapon} count _allPylonWeapons) == 1) then {
GVAR(currentAircraft) removeWeaponGlobal _pylonWeapon;
TRACE_2("Removing unused weapon",_pylonWeapon,_allPylonWeapons);
_weaponToRemove = _pylonWeapon;
};
};
@ -47,7 +50,7 @@ if (_currentPylon == count _pylonsToConfigure) exitWith {};
[
QGVAR(setPylonLoadOutEvent),
[GVAR(currentAircraft), _pylonIndex + 1, _pylonMagazine, _turret]
[GVAR(currentAircraft), _pylonIndex + 1, _pylonMagazine, _turret, _weaponToRemove]
] call CBA_fnc_globalEvent;
private _count = if (GVAR(rearmNewPylons) || {GVAR(isCurator)}) then {

View File

@ -149,7 +149,10 @@ if (!GVAR(isCurator)) then {
isNull (GVAR(currentAircraft) getVariable [QGVAR(currentUser), objNull]) ||
{(ace_player distanceSqr GVAR(currentAircraft)) > GVAR(searchDistanceSqr)}
}, {
[localize LSTRING(TooFar), false, 5] call EFUNC(common,displayText);
TRACE_3("disconnect/far",GVAR(currentAircraft),ace_player distance GVAR(currentAircraft),GVAR(currentAircraft) getVariable QGVAR(currentUser));
if ((ace_player distanceSqr GVAR(currentAircraft)) > GVAR(searchDistanceSqr)) then {
[localize LSTRING(TooFar), false, 5] call EFUNC(common,displayText);
};
call FUNC(onButtonClose);
}] call CBA_fnc_waitUntilAndExecute;
};