2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-07-14 14:16:53 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi, commy2
|
2024-01-27 08:14:10 +00:00
|
|
|
* Handles all incoming damage for boxes.
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2017-06-08 13:31:51 +00:00
|
|
|
* HandleDamage EH <ARRAY>
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2024-01-27 08:14:10 +00:00
|
|
|
* Damage to be inflicted (can be nil) <NUMBER>
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2021-10-17 20:01:41 +00:00
|
|
|
* _this call ace_cookoff_fnc_handleDamageBox
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
params ["_box", "", "_damage", "_source", "_ammo", "_hitIndex", "_instigator"];
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
if (!local _box) exitWith {};
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
// If it's already dead, ignore
|
|
|
|
if (damage _box >= 1) exitWith {};
|
2019-11-05 17:55:15 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
// If cookoff for boxes is disabled, exit
|
|
|
|
if (!GVAR(enableAmmobox) || {GVAR(ammoCookoffDuration) == 0}) exitWith {};
|
|
|
|
|
|
|
|
if !(_box getVariable [QGVAR(enableAmmoCookoff), true]) exitWith {};
|
|
|
|
|
|
|
|
// Get hitpoint name
|
2016-07-14 14:16:53 +00:00
|
|
|
private _hitpoint = "#structural";
|
|
|
|
|
|
|
|
if (_hitIndex != -1) then {
|
2024-01-27 08:14:10 +00:00
|
|
|
_hitpoint = ((getAllHitPointsDamage _box) param [0, []]) select _hitIndex;
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
if !(_hitpoint == "#structural" && {_damage > 0.5}) exitWith {};
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
// Catch fire when hit by an explosive round
|
|
|
|
if (IS_EXPLOSIVE_AMMO(_ammo)) then {
|
|
|
|
[QGVAR(cookOffBox), [_box, _source, _instigator]] call CBA_fnc_serverEvent;
|
2016-07-14 14:16:53 +00:00
|
|
|
} else {
|
2024-01-27 08:14:10 +00:00
|
|
|
// Get change in damage
|
|
|
|
private _oldDamage = if (_hitpoint == "#structural") then {
|
|
|
|
damage _box
|
|
|
|
} else {
|
|
|
|
_box getHitIndex _hitIndex
|
|
|
|
};
|
|
|
|
|
|
|
|
// There is a small chance of cooking a box off if it's shot by tracer ammo
|
|
|
|
if !(random 1 < _oldDamage * 0.05) exitWith {};
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
// Need magazine to check for tracers
|
|
|
|
private _magazine = if (_source == _instigator) then {
|
|
|
|
currentMagazine _source
|
2016-07-14 14:16:53 +00:00
|
|
|
} else {
|
2024-01-27 08:14:10 +00:00
|
|
|
_source currentMagazineTurret (_box unitTurret _instigator)
|
|
|
|
};
|
|
|
|
|
|
|
|
private _configMagazine = configFile >> "CfgMagazines" >> _magazine;
|
|
|
|
|
|
|
|
// Magazine could have changed during flight time (just ignore if so)
|
|
|
|
if (getText (_configMagazine >> "ammo") == _ammo) then {
|
|
|
|
// If magazine's tracer density is high enough then low chance for cook off
|
|
|
|
private _tracers = getNumber (_configMagazine >> "tracersEvery");
|
2021-10-14 15:49:27 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
if (_tracers >= 1 && {_tracers <= 4}) then {
|
|
|
|
[QGVAR(cookOffBox), [_box, _source, _instigator]] call CBA_fnc_serverEvent;
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
|
|
|
};
|
2016-10-06 20:37:38 +00:00
|
|
|
};
|
2024-01-27 08:14:10 +00:00
|
|
|
|
|
|
|
// Prevent destruction, let cook-off handle it if necessary
|
|
|
|
_damage min 0.89
|