From 217536cebeb41a9a81c81a4135f37b2764ff49ee Mon Sep 17 00:00:00 2001 From: Steve Zhao Date: Sun, 9 Jan 2022 23:50:29 -0500 Subject: [PATCH] add cookoff via dummy --- addons/overheating/XEH_PREP.hpp | 4 ++ .../functions/fnc_cookoffWeapon.sqf | 8 +++- .../functions/fnc_cookoffWeaponDummy.sqf | 48 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 addons/overheating/functions/fnc_cookoffWeaponDummy.sqf diff --git a/addons/overheating/XEH_PREP.hpp b/addons/overheating/XEH_PREP.hpp index 865a049569..04239cdc49 100644 --- a/addons/overheating/XEH_PREP.hpp +++ b/addons/overheating/XEH_PREP.hpp @@ -1,3 +1,6 @@ +// testing, update fncs on the fly +#undef PREP +#define PREP(var1) TRIPLES(ADDON,fnc,var1) = { call compile preProcessFileLineNumbers '\MAINPREFIX\PREFIX\SUBPREFIX\COMPONENT_F\functions\DOUBLES(fnc,var1).sqf' } PREP(calculateCooling); PREP(canUnjam); @@ -8,6 +11,7 @@ PREP(checkSpareBarrelsTemperatures); PREP(checkTemperature); PREP(clearJam); PREP(cookoffWeapon); +PREP(cookoffWeaponDummy); PREP(coolWeaponWithItem); PREP(coolWeaponWithWaterSource); PREP(displayTemperature); diff --git a/addons/overheating/functions/fnc_cookoffWeapon.sqf b/addons/overheating/functions/fnc_cookoffWeapon.sqf index ae2311243c..052f064adc 100644 --- a/addons/overheating/functions/fnc_cookoffWeapon.sqf +++ b/addons/overheating/functions/fnc_cookoffWeapon.sqf @@ -49,7 +49,13 @@ if !(_mode in _modes) then { params ["_unit", "_mode", "_muzzle", "_muzzleCache"]; // fire the cookoff - _unit forceWeaponFire [_muzzle, _mode]; + private _canFire = false; // check for animation here + + if (_canFire) then { + _unit forceWeaponFire [_muzzle, _mode]; + } else { + [_unit, _mode, _muzzle] call FUNC(cookoffWeaponDummy); + }; // switch back to the cached muzzle if required if (_muzzle != _muzzleCache) then { diff --git a/addons/overheating/functions/fnc_cookoffWeaponDummy.sqf b/addons/overheating/functions/fnc_cookoffWeaponDummy.sqf new file mode 100644 index 0000000000..31856848d1 --- /dev/null +++ b/addons/overheating/functions/fnc_cookoffWeaponDummy.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Create dummy with weapon that is cooking off for when actual weapon will not fire + * + * Arguments: + * 0: Input + * + * Return Value: + * NONE + * + * Example: + * [player, currentWeaponMode player, currentMuzzle player] call ace_overheating_fnc_cookoffWeaponDummy + */ + +params ["_unit", "_mode", "_muzzle", ["_loadout", []], ["_animation", ""], ["_proxy", ""]]; + +private _unitLoadout = getUnitLoadout _unit; +if (_muzzle == primaryWeapon _unit) then { + _loadout = [_unitLoadout select 0,[],[],[],[],[],"","",[],["","","","","",""]]; + _proxy = "proxy:\a3\characters_f\proxies\weapon.001"; + _animation = "AmovPercMstpSrasWrflDnon"; +} else { + _loadout = [[],[],_unitLoadout select 2,[],[],[],"","",[],["","","","","",""]]; + _proxy = "proxy:\a3\characters_f\proxies\pistol.001"; + _animation = "AmovPercMstpSrasWpstDnon"; +}; + +private _dummy = _unit getVariable [format [QGVAR(%1_dummy), _muzzle], objNull]; +if (isNull _dummy) then { + _dummy = createAgent [QGVAR(dummy), [0, 0, 0], [], 0, "CAN_COLLIDE"]; +}; +_dummy setUnitLoadout _loadout; +_dummy disableAI "ALL"; +_dummy allowDamage false; +_dummy switchmove _animation; +_dummy attachTo [_unit, [0, 0, 0], _proxy, true]; + +//_dummy addEventHandler ["Deleted", {}]; +_dummy forceWeaponFire [_muzzle, _mode]; +_unit setAmmo [_muzzle, (_unit ammo _muzzle) - 1]; + +private _isNextRoundCool = true; // reuse dummy if next round is also going to be cooked off +if (_isNextRoundCool) then { + deleteVehicle _dummy; +} else { + _unit setVariable [format [QGVAR(%1_dummy), _muzzle], _dummy]; +};