From 32846014a1b72a115805c488ebe7fb9e2effde1a Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Mon, 14 Mar 2016 14:21:02 +0100 Subject: [PATCH] fix ammo handling init on dedicated --- addons/mk6mortar/XEH_postInit.sqf | 2 ++ .../fnc_handlePlayerVehicleChanged.sqf | 29 +++++++++---------- addons/mk6mortar/functions/fnc_mortarInit.sqf | 13 +++++---- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/addons/mk6mortar/XEH_postInit.sqf b/addons/mk6mortar/XEH_postInit.sqf index 5c82d55f50..9c098b8cdd 100644 --- a/addons/mk6mortar/XEH_postInit.sqf +++ b/addons/mk6mortar/XEH_postInit.sqf @@ -15,6 +15,8 @@ _static setMagazineTurretAmmo [_magazine, _ammoCount, [0]]; }] call EFUNC(common,addEventHandler); +["initMortar", {_this call FUNC(mortarInit);}] call EFUNC(common,addEventHandler); + if (!hasInterface) exitWith {}; ["playerVehicleChanged", {_this call FUNC(handlePlayerVehicleChanged);}] call EFUNC(common,addEventHandler); diff --git a/addons/mk6mortar/functions/fnc_handlePlayerVehicleChanged.sqf b/addons/mk6mortar/functions/fnc_handlePlayerVehicleChanged.sqf index 02049289aa..2d921973d4 100644 --- a/addons/mk6mortar/functions/fnc_handlePlayerVehicleChanged.sqf +++ b/addons/mk6mortar/functions/fnc_handlePlayerVehicleChanged.sqf @@ -16,31 +16,30 @@ */ #include "script_component.hpp" -PARAMS_2(_player,_newVehicle); - -private["_tubeWeaponName" ,"_fireModes", "_lastFireMode"]; +params ["_player", "_newVehicle"]; if (isNull _newVehicle) exitWith {}; if (!(_newVehicle isKindOf "Mortar_01_base_F")) exitWith {}; // Run magazine handling initialization if enabled -if (!EGVAR(common,settingsInitFinished)) then { - EGVAR(common,runAtSettingsInitialized) pushBack [{ - if (GVAR(useAmmoHandling) && {!(_this getVariable [QGVAR(initialized),false]) && !(_this getVariable [QGVAR(exclude),false])}) then { - _this call FUNC(mortarInit); +if (!(_newVehicle getVariable [QGVAR(initialized),false]) && !(_newVehicle getVariable [QGVAR(exclude),false])) then { + // Make sure that mortar init is executed after settings init + [{ + params ["_mortar"]; + if (GVAR(useAmmoHandling) && {!(_mortar getVariable [QGVAR(initialized),false]) && !(_mortar getVariable [QGVAR(exclude),false])}) then { + //wait for proper turret locality change + [{ + ["initMortar", [_this], [_this]] call EFUNC(common,globalEvent); + }, _mortar, 0.05] call EFUNC(common,waitAndExecute); }; - }, _newVehicle]; -} else { - if (GVAR(useAmmoHandling) && {!(_newVehicle getVariable [QGVAR(initialized),false]) && !(_newVehicle getVariable [QGVAR(exclude),false])}) then { - _newVehicle call FUNC(mortarInit); - }; + }, _newVehicle] call EFUNC(common,runAfterSettingsInit); }; -_tubeWeaponName = (weapons _newVehicle) select 0; -_fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes"); +private _tubeWeaponName = (weapons _newVehicle) select 0; +private _fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes"); //Restore last firemode: -_lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1]; +private _lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1]; if (_lastFireMode != -1) then { _player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode]; }; diff --git a/addons/mk6mortar/functions/fnc_mortarInit.sqf b/addons/mk6mortar/functions/fnc_mortarInit.sqf index 7c74cb8249..68c9eab91e 100644 --- a/addons/mk6mortar/functions/fnc_mortarInit.sqf +++ b/addons/mk6mortar/functions/fnc_mortarInit.sqf @@ -18,27 +18,28 @@ params ["_mortar"]; if (_mortar getVariable [QGVAR(initialized),false] || _mortar getVariable [QGVAR(exclude),false]) exitWith {TRACE_1("Exit",_mortar)}; +if (!(_mortar turretLocal [0])) exitWith {TRACE_1("Exit - turret not local",_mortar)}; -// Remove all magazines +// Remove all magazines from turret if (count magazines _mortar > 0) then { { - [QGVAR(removeMagazine), [_mortar, _x]] call EFUNC(common,globalEvent); + _mortar removeMagazineTurret [_x,[0]]; } forEach magazines _mortar; }; -// Replace current weapon with ammo handling weapon +// Replace current turret weapon with ammo handling weapon private _currentWeapon = _mortar weaponsTurret [0] select 0; private _newWeapon = ""; -if (_currentWeapon == "mortar_82mm") then { +if (tolower _currentWeapon == "mortar_82mm") then { _newWeapon = "ace_mortar_82mm"; } else { _newWeapon = getText (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(replaceWith)); }; if (_newWeapon != "") then { - _mortar removeWeaponGlobal _currentWeapon; - _mortar addWeaponGlobal _newWeapon; + _mortar removeWeaponTurret [_currentWeapon,[0]]; + _mortar addWeaponTurret [_newWeapon,[0]]; }; _mortar setVariable [QGVAR(initialized),true,true];