diff --git a/functions/linearSD/cfgFunctions.hpp b/functions/linearSD/cfgFunctions.hpp index 75741db..2327967 100644 --- a/functions/linearSD/cfgFunctions.hpp +++ b/functions/linearSD/cfgFunctions.hpp @@ -25,5 +25,6 @@ class grad_linearSD { class startLinearSD {}; class startNewRound {}; class startTimeout {}; + class transferRadiosAcrossRespawn {}; }; }; diff --git a/functions/linearSD/fn_startLinearSD.sqf b/functions/linearSD/fn_startLinearSD.sqf index b1098ea..495c5a5 100644 --- a/functions/linearSD/fn_startLinearSD.sqf +++ b/functions/linearSD/fn_startLinearSD.sqf @@ -5,6 +5,7 @@ params [["_startingSectorID",-1],["_roundLength",60],["_opforDirection",1],["_da if (hasInterface) then { [] call FUNC(addTeleportAction); [] call FUNC(addChatCommands); + [] call FUNC(transferRadiosAcrossRespawn); if (didJIP) then { [{!isNull player},FUNC(movePlayerToRespawnPos),[]] call CBA_fnc_waitUntilAndExecute; diff --git a/functions/linearSD/fn_transferRadiosAcrossRespawn.sqf b/functions/linearSD/fn_transferRadiosAcrossRespawn.sqf new file mode 100644 index 0000000..886b305 --- /dev/null +++ b/functions/linearSD/fn_transferRadiosAcrossRespawn.sqf @@ -0,0 +1,89 @@ +#include "component.hpp" + +// save entire settings array once anything is changed basically +private _fnc_saveSWSettings = { + params ["_unit"]; + if (_unit != player) exitWith {}; + player setVariable [QGVAR(swSettings),(call TFAR_fnc_activeSwRadio) call TFAR_fnc_getSwSettings]; +}; +{[_x,_fnc_saveSWSettings] call CBA_fnc_addEventHandler} forEach [ + "TFAR_event_OnSWchannelSet", + "TFAR_event_OnSWstereoSet", + "TFAR_event_OnSWvolumeSet", + "TFAR_event_OnSWChange", + "TFAR_event_OnSWspeakersSet" +]; + +// same for longrange +private _fnc_saveLRSettings = { + params ["_unit"]; + if (_unit != player) exitWith {}; + player setVariable [QGVAR(lrSettings),(call TFAR_fnc_activeLrRadio) call TFAR_fnc_getLrSettings]; +}; +{[_x,_fnc_saveLRSettings] call CBA_fnc_addEventHandler} forEach [ + "TFAR_event_OnLRchannelSet", + "TFAR_event_OnLRstereoSet", + "TFAR_event_OnLRvolumeSet", + "TFAR_event_OnLRChange", + "TFAR_event_OnLRspeakersSet" +]; + +// frequency changed event gets special treatment, because it fires for both sw and lr +[ + "TFAR_event_OnFrequencyChanged", + { + params ["_unit","_radio"]; + if (_unit != player) exitWith {}; + + private _activeSw = call TFAR_fnc_activeSwRadio; + if (_activeSw isEqualTo _radio) exitWith { + player setVariable [QGVAR(swSettings),(call TFAR_fnc_activeSwRadio) call TFAR_fnc_getSwSettings]; + }; + + private _activeLr = call TFAR_fnc_activeLRRadio; + if (_activeLr isEqualTo _radio) exitWith { + player setVariable [QGVAR(lrSettings),(call TFAR_fnc_activeLrRadio) call TFAR_fnc_getLrSettings]; + }; + } +] call CBA_fnc_addEventHandler; + +// apply SR settings every time a radio is instanced +[ + "TFAR_event_OnRadiosReceived", + { + params ["_unit","_radio"]; + if (_unit != player) exitWith {}; + private _settings = player getVariable [QGVAR(swSettings),[]]; + if (count _settings > 0) then { + [call TFAR_fnc_activeSwRadio, _settings] call TFAR_fnc_setSwSettings; + }; + } +] call CBA_fnc_addEventHandler; + +// apply LR settings every time a new loadout is applied +[ + "grad_loadout_loadoutApplied", + { + params ["_unit","_loadout"]; + if (_unit != player) exitWith {}; + + private _backpack = (_loadout param [5,[]]) param [0,""]; + if !(_backpack call TFAR_fnc_isLRRadio) exitWith {}; + + private _settings = player getVariable [QGVAR(lrSettings),[]]; + if (count _settings > 0) then { + [ + { + params ["_unit","_backpack"]; + backpack _unit == _backpack + }, + { + params ["_unit","","_settings"]; + [call TFAR_fnc_activeLrRadio, _settings] call TFAR_fnc_setLrSettings; + }, + [_unit,_backpack,_settings], + 5 + ] call CBA_fnc_waitUntilAndExecute; + }; + } +] call CBA_fnc_addEventHandler;