fix ammo handling init on dedicated

This commit is contained in:
SzwedzikPL 2016-03-14 14:21:02 +01:00
parent 1ffd23c193
commit 32846014a1
3 changed files with 23 additions and 21 deletions

View File

@ -15,6 +15,8 @@
_static setMagazineTurretAmmo [_magazine, _ammoCount, [0]]; _static setMagazineTurretAmmo [_magazine, _ammoCount, [0]];
}] call EFUNC(common,addEventHandler); }] call EFUNC(common,addEventHandler);
["initMortar", {_this call FUNC(mortarInit);}] call EFUNC(common,addEventHandler);
if (!hasInterface) exitWith {}; if (!hasInterface) exitWith {};
["playerVehicleChanged", {_this call FUNC(handlePlayerVehicleChanged);}] call EFUNC(common,addEventHandler); ["playerVehicleChanged", {_this call FUNC(handlePlayerVehicleChanged);}] call EFUNC(common,addEventHandler);

View File

@ -16,31 +16,30 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_player,_newVehicle); params ["_player", "_newVehicle"];
private["_tubeWeaponName" ,"_fireModes", "_lastFireMode"];
if (isNull _newVehicle) exitWith {}; if (isNull _newVehicle) exitWith {};
if (!(_newVehicle isKindOf "Mortar_01_base_F")) exitWith {}; if (!(_newVehicle isKindOf "Mortar_01_base_F")) exitWith {};
// Run magazine handling initialization if enabled // Run magazine handling initialization if enabled
if (!EGVAR(common,settingsInitFinished)) then { if (!(_newVehicle getVariable [QGVAR(initialized),false]) && !(_newVehicle getVariable [QGVAR(exclude),false])) then {
EGVAR(common,runAtSettingsInitialized) pushBack [{ // Make sure that mortar init is executed after settings init
if (GVAR(useAmmoHandling) && {!(_this getVariable [QGVAR(initialized),false]) && !(_this getVariable [QGVAR(exclude),false])}) then { [{
_this call FUNC(mortarInit); params ["_mortar"];
}; if (GVAR(useAmmoHandling) && {!(_mortar getVariable [QGVAR(initialized),false]) && !(_mortar getVariable [QGVAR(exclude),false])}) then {
}, _newVehicle]; //wait for proper turret locality change
} else { [{
if (GVAR(useAmmoHandling) && {!(_newVehicle getVariable [QGVAR(initialized),false]) && !(_newVehicle getVariable [QGVAR(exclude),false])}) then { ["initMortar", [_this], [_this]] call EFUNC(common,globalEvent);
_newVehicle call FUNC(mortarInit); }, _mortar, 0.05] call EFUNC(common,waitAndExecute);
}; };
}, _newVehicle] call EFUNC(common,runAfterSettingsInit);
}; };
_tubeWeaponName = (weapons _newVehicle) select 0; private _tubeWeaponName = (weapons _newVehicle) select 0;
_fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes"); private _fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes");
//Restore last firemode: //Restore last firemode:
_lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1]; private _lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1];
if (_lastFireMode != -1) then { if (_lastFireMode != -1) then {
_player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode]; _player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode];
}; };

View File

@ -18,27 +18,28 @@
params ["_mortar"]; params ["_mortar"];
if (_mortar getVariable [QGVAR(initialized),false] || _mortar getVariable [QGVAR(exclude),false]) exitWith {TRACE_1("Exit",_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 { if (count magazines _mortar > 0) then {
{ {
[QGVAR(removeMagazine), [_mortar, _x]] call EFUNC(common,globalEvent); _mortar removeMagazineTurret [_x,[0]];
} forEach magazines _mortar; } 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 _currentWeapon = _mortar weaponsTurret [0] select 0;
private _newWeapon = ""; private _newWeapon = "";
if (_currentWeapon == "mortar_82mm") then { if (tolower _currentWeapon == "mortar_82mm") then {
_newWeapon = "ace_mortar_82mm"; _newWeapon = "ace_mortar_82mm";
} else { } else {
_newWeapon = getText (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(replaceWith)); _newWeapon = getText (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(replaceWith));
}; };
if (_newWeapon != "") then { if (_newWeapon != "") then {
_mortar removeWeaponGlobal _currentWeapon; _mortar removeWeaponTurret [_currentWeapon,[0]];
_mortar addWeaponGlobal _newWeapon; _mortar addWeaponTurret [_newWeapon,[0]];
}; };
_mortar setVariable [QGVAR(initialized),true,true]; _mortar setVariable [QGVAR(initialized),true,true];