Skip to content

Commit

Permalink
linearSD: close #26 save radio settings across rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
McDiod committed Jun 23, 2019
1 parent beeef83 commit f04130f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions functions/linearSD/cfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ class grad_linearSD {
class startLinearSD {};
class startNewRound {};
class startTimeout {};
class transferRadiosAcrossRespawn {};
};
};
1 change: 1 addition & 0 deletions functions/linearSD/fn_startLinearSD.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
89 changes: 89 additions & 0 deletions functions/linearSD/fn_transferRadiosAcrossRespawn.sqf
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit f04130f

Please sign in to comment.