2016-07-14 14:16:53 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
[QGVAR(cookOff), LINKFUNC(cookOff)] call CBA_fnc_addEventHandler;
|
|
|
|
[QGVAR(cookOffBoxLocal), LINKFUNC(cookOffBoxLocal)] call CBA_fnc_addEventHandler;
|
|
|
|
[QGVAR(cookOffEffect), LINKFUNC(cookOffEffect)] call CBA_fnc_addEventHandler;
|
|
|
|
[QGVAR(engineFireLocal), LINKFUNC(engineFireLocal)] call CBA_fnc_addEventHandler;
|
|
|
|
[QGVAR(smoke), LINKFUNC(smoke)] call CBA_fnc_addEventHandler;
|
|
|
|
|
|
|
|
if (isServer) then {
|
|
|
|
[QGVAR(cookOffBox), LINKFUNC(cookOffBox)] call CBA_fnc_addEventHandler;
|
|
|
|
[QGVAR(engineFire), LINKFUNC(engineFire)] call CBA_fnc_addEventHandler;
|
|
|
|
[QGVAR(detonateAmmunition), LINKFUNC(detonateAmmunition)] call CBA_fnc_addEventHandler;
|
|
|
|
};
|
2016-08-23 07:57:54 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
// Handle cleaning up effects when vehicle is deleted mid cook-off
|
2022-07-15 14:59:49 +00:00
|
|
|
[QGVAR(addCleanupHandlers), {
|
2024-01-27 08:14:10 +00:00
|
|
|
// No effects on machines without interfaces
|
|
|
|
if (!hasInterface) exitWith {};
|
|
|
|
|
|
|
|
params ["_object"];
|
|
|
|
|
|
|
|
// Don't add a new EH if cook-off is run multiple times
|
|
|
|
if (!isNil {_object getVariable QGVAR(deletedEH)}) exitWith {};
|
|
|
|
|
|
|
|
_object setVariable [QGVAR(deletedEH),
|
|
|
|
_object addEventHandler ["Deleted", {
|
|
|
|
[QGVAR(cleanupEffects), _this select 0] call CBA_fnc_localEvent;
|
|
|
|
}]
|
|
|
|
];
|
2022-07-15 14:59:49 +00:00
|
|
|
}] call CBA_fnc_addEventHandler;
|
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
[QGVAR(cleanupEffects), {
|
2024-01-27 08:14:10 +00:00
|
|
|
params ["_object", ["_effects", []]];
|
|
|
|
|
|
|
|
if (isServer) then {
|
|
|
|
// Reset, so that object can cook-off again
|
|
|
|
_object setVariable [QGVAR(isCookingOff), nil, true];
|
|
|
|
|
|
|
|
// Remove effects from JIP
|
|
|
|
private _jipID = _object getVariable QGVAR(jipID);
|
2021-10-30 21:42:03 +00:00
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
if (isNil "_jipID") exitWith {};
|
|
|
|
|
|
|
|
_jipID call CBA_fnc_removeGlobalEventJIP;
|
|
|
|
|
|
|
|
_object setVariable [QGVAR(jipID), nil];
|
2016-10-28 20:10:40 +00:00
|
|
|
};
|
2024-01-27 08:14:10 +00:00
|
|
|
|
|
|
|
// No effects on machines without interfaces
|
|
|
|
if (!hasInterface) exitWith {};
|
|
|
|
|
|
|
|
// All effects are local
|
|
|
|
_effects append (_object getVariable [QGVAR(effects), []]);
|
|
|
|
|
|
|
|
if (_effects isEqualTo []) exitWith {};
|
|
|
|
|
|
|
|
{
|
|
|
|
deleteVehicle _x;
|
|
|
|
} forEach _effects;
|
|
|
|
|
|
|
|
_object setVariable [QGVAR(effects), nil];
|
2021-10-14 15:49:27 +00:00
|
|
|
}] call CBA_fnc_addEventHandler;
|
2016-10-28 20:10:40 +00:00
|
|
|
|
2016-10-06 20:37:38 +00:00
|
|
|
["ReammoBox_F", "init", {
|
2024-01-27 08:14:10 +00:00
|
|
|
// Calling this function inside curly brackets allows the usage of "exitWith", which would be broken with "HandleDamage" otherwise
|
|
|
|
(_this select 0) addEventHandler ["HandleDamage", {_this call FUNC(handleDamageBox)}];
|
2016-10-06 20:37:38 +00:00
|
|
|
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
|
|
|
|
|
2024-01-27 08:14:10 +00:00
|
|
|
// Secondary explosions
|
|
|
|
["AllVehicles", "Killed", {
|
|
|
|
if (!GVAR(enableAmmoCookoff) || {GVAR(ammoCookoffDuration) == 0}) exitWith {};
|
|
|
|
|
2021-02-23 17:42:15 +00:00
|
|
|
params ["_vehicle", "", "", "_useEffects"];
|
2024-01-27 08:14:10 +00:00
|
|
|
|
|
|
|
if (_useEffects && {_vehicle getVariable [QGVAR(enableAmmoCookoff), true]}) then {
|
2024-02-03 16:48:54 +00:00
|
|
|
[QGVAR(detonateAmmunition), [_vehicle, false, objNull, objNull, (random MAX_AMMO_DETONATION_START_DELAY) max MIN_AMMO_DETONATION_START_DELAY]] call CBA_fnc_serverEvent;
|
2016-08-13 10:12:34 +00:00
|
|
|
};
|
2024-01-27 08:14:10 +00:00
|
|
|
}, nil, ["CAManBase", "StaticWeapon"]] call CBA_fnc_addClassEventHandler;
|
2024-02-04 09:36:59 +00:00
|
|
|
|
|
|
|
if (hasInterface) then {
|
|
|
|
// Plays a sound locally, so that different sounds can be used for various distances
|
|
|
|
[QGVAR(playCookoffSound), {
|
|
|
|
params ["_object", "_sound"];
|
|
|
|
|
|
|
|
if (isNull _object) exitWith {};
|
|
|
|
|
|
|
|
private _distance = _object distance (positionCameraToWorld [0, 0, 0]);
|
|
|
|
|
2024-02-04 09:55:09 +00:00
|
|
|
TRACE_2("",_object,_sound);
|
2024-02-04 09:36:59 +00:00
|
|
|
|
|
|
|
// 3 classes of distances: close, mid and far, each having different sound files
|
|
|
|
private _classDistance = switch (true) do {
|
|
|
|
case (_distance < DISTANCE_CLOSE): {"close"};
|
|
|
|
case (_distance < DISTANCE_MID): {"mid"};
|
|
|
|
default {"far"};
|
|
|
|
};
|
|
|
|
|
|
|
|
_sound = format [QGVAR(%1_%2_%3), _sound, _classDistance, floor (random 3) + 1];
|
|
|
|
|
|
|
|
TRACE_1("",_sound);
|
|
|
|
|
|
|
|
// Allows other mods to change sounds for cook-off
|
|
|
|
_sound = getArray (configFile >> "CfgSounds" >> _sound >> "sound");
|
|
|
|
|
|
|
|
if (_sound isEqualTo []) exitWith {};
|
|
|
|
|
|
|
|
_sound params ["_sound", "_volume", "_pitch", "_maxDistance"];
|
|
|
|
|
|
|
|
if (_distance > _maxDistance) exitWith {};
|
|
|
|
|
|
|
|
// Make sure file exists, so RPT isn't spammed with non-existent entry errors
|
|
|
|
if (!fileExists _sound) exitWith {};
|
|
|
|
|
|
|
|
// Obeys speed of sound and takes doppler effects into account
|
|
|
|
playSound3D [_sound, objNull, insideBuilding _object >= 0.5, getPosASL _object, _volume, _pitch + (random 0.2) - 0.1, _maxDistance, 0, true];
|
|
|
|
}] call CBA_fnc_addEventHandler;
|
|
|
|
};
|