Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medical Feedback - Set volume and radio usage based current unit #7529

Merged
merged 6 commits into from
Feb 22, 2020

Conversation

Whigital
Copy link
Contributor

@Whigital Whigital commented Feb 15, 2020

When merged this pull request will:

  • Set players volume based on unconscious state

Fix #7528

@jonpas jonpas changed the title Medical_Status - Fix players volume based on unconsciousness Medical Status - Fix players volume based on unconsciousness Feb 15, 2020
@jonpas jonpas added the kind/bug-fix Release Notes: **FIXED:** label Feb 15, 2020
@jonpas jonpas added this to the 3.13.1 milestone Feb 15, 2020
Co-Authored-By: jonpas <jonpas33@gmail.com>
@kymckay
Copy link
Member

kymckay commented Feb 17, 2020

I don't think this is such a simple fix as assumed here because the unconscious state of the local machine can change without hitting the setUnconsciousState function (for example, upon death or upon unit switching).

See:

["ace_unconscious", {
params ["_unit", "_unconscious"];
if (_unit != ACE_player) exitWith {};
TRACE_1("player unconscious eh",_unconscious);
if (_unconscious && {cameraView == "GUNNER"} && {(vehicle _unit) != _unit} && {cameraOn == vehicle _unit}) then {
TRACE_2("exiting gunner view",cameraOn,cameraView);
ACE_player switchCamera "INTERNAL";
};
// Toggle unconscious player's ability to talk in radio addons
if (["task_force_radio"] call EFUNC(common,isModLoaded)) then {
_unit setVariable ["tf_voiceVolume", [1, 0] select _unconscious, true];
_unit setVariable ["tf_unable_to_use_radio", _unconscious]; // Only used locally
};
if (["acre_main"] call EFUNC(common,isModLoaded)) then {
_unit setVariable ["acre_sys_core_isDisabled", _unconscious, true];
};
// Greatly reduce player's hearing ability while unconscious (affects radio addons)
[QUOTE(ADDON), VOL_UNCONSCIOUS, _unconscious] call EFUNC(common,setHearingCapability);
[true] call FUNC(handleEffects);
["unconscious", _unconscious] call EFUNC(common,setDisableUserInputStatus);
}] call CBA_fnc_addEventHandler;
// Reset volume upon death for spectators
[QEGVAR(medical,death), {
params ["_unit"];
if (_unit != ACE_player) exitWith {};
if (["task_force_radio"] call EFUNC(common,isModLoaded)) then {
_unit setVariable ["tf_voiceVolume", 1, true];
_unit setVariable ["tf_unable_to_use_radio", false];
};
if (["acre_main"] call EFUNC(common,isModLoaded)) then {
_unit setVariable ["acre_sys_core_isDisabled", false, true];
};
[QUOTE(ADDON), 1, false] call EFUNC(common,setHearingCapability);
}] call CBA_fnc_addEventHandler;
// Update effects to match new unit's current status (this also handles respawn)
["unit", {
params ["_new"];
private _status = IS_UNCONSCIOUS(_new);
if (["task_force_radio"] call EFUNC(common,isModLoaded)) then {
_new setVariable ["tf_voiceVolume", [1, 0] select _status, true];
_new setVariable ["tf_unable_to_use_radio", _status];
};
if (["acre_main"] call EFUNC(common,isModLoaded)) then {
_new setVariable ["acre_sys_core_isDisabled", _status, true];
};
[QUOTE(ADDON), VOL_UNCONSCIOUS, _status] call EFUNC(common,setHearingCapability);
[true] call FUNC(handleEffects);
["unconscious", _status] call EFUNC(common,setDisableUserInputStatus);
}] call CBA_fnc_addPlayerEventHandler;

@Whigital
Copy link
Contributor Author

Moving the EFUNC(common,setVolume) call from ace_medical_status_fnc_setUnconsciousState -> medical_feedback/XEH_postInit (ace_unconscious EH and unit playerEH) should suffice ?

From what i can see, the only place the event gets raised is at the end of ace_medical_status_fnc_setUnconsciousState.

Volume gets restored upon respawn, so might not be necessary on ace_medical_death event ?

[true] call FUNC(setVolume);

@kymckay
Copy link
Member

kymckay commented Feb 18, 2020

@Whigital I would include on death because death does not always immediately lead to respawn and could be filled with other systems (most commonly spectator time).

However, on death it would only apply when the _unit == player since setVolume updates the player's sound specifically (and death of any ACE_player !== player results in a unit change back to player which triggers the unit event).

In fact, it should probably be clarified how TFAR and ACRE handle the unit variables that function is setting (always on player), I would assume that they only apply for that unit and those addons aren't just using player as a storage vessel. If they are unit specific then that function would be much more useful for us here if you could pass in a unit parameter.

@jonpas
Copy link
Member

jonpas commented Feb 18, 2020

ACRE uses a similar system to ace_player.

@kymckay
Copy link
Member

kymckay commented Feb 18, 2020

Figured as much, then the way I would fix this is add an option parameter to the common function to pass in a unit, and just update all three events in feedback postInit to call that function and pass in the unit if it's ace_player

@Whigital
Copy link
Contributor Author

Whigital commented Feb 18, 2020

  • Update ace_common_fnc_setVolume with something like
params [
    ["_setVolume", false],
    ["_unit", player]
];
  • Update the setvar's in ace_common_fnc_setVolume with _unit instead of player.

  • Update medical_feedback/XEH_postInit with [<true|false>, _unit] call EFUNC(common,setVolume) for ace_unconscious and ace_medical_deathevents (checks for ACE_player alredy there).

  • For the unit EH in medical_feedback/XEH_postInit, check for ACE_player.

if (_new == ACE_player) then {
    [<true|false>, _new] call EFUNC(common,setVolume)
};

@kymckay
Copy link
Member

kymckay commented Feb 18, 2020

That sound right 👍

Only thing is the "unit" event _new is ACE_player by definition so no need to check that. Also note you can replace the existing lines which set TFAR and ACRE variables in all those EHs.

@Whigital
Copy link
Contributor Author

Whigital commented Feb 18, 2020

Beautify the setVolume function and get rid of the if statement ?

private _vol = ([MUTED_LEVEL, NORMAL_LEVEL] select _setVolume);
private _voice = ([NO_SOUND, NORMAL_LEVEL] select _setVolume);

2 fadeSound _vol;

//TFAR
_unit setVariable ["tf_voiceVolume", _voice , true];
_unit setVariable ["tf_globalVolume", _vol];
_unit setVariable ["tf_unable_to_use_radio", !_setVolume];

// ACRE2
if (!isNil "acre_api_fnc_setGlobalVolume") then { [_vol^0.33] call acre_api_fnc_setGlobalVolume; };
_unit setVariable ["acre_sys_core_isDisabled", !_setVolume, true];

@kymckay
Copy link
Member

kymckay commented Feb 18, 2020

Feel free to do so, current changes look correct to me

I also notice we're calling the setHearingCapability function which looks like it has some overlap with this setVolume function (both interact with fadeSound, tf_globalVolume and acre_api_fnc_setGlobalVolume).

This area of the code could probably use some cleanup (would avoid that for this PR and just focus on the fix, just noting for other ace devs).

@Whigital
Copy link
Contributor Author

Roger. Will keep the changes in this PR to just fixing the issue at hand.

@Whigital
Copy link
Contributor Author

Think i'll leave this PR as is. Will verify functionality and report back.

@Whigital Whigital changed the title Medical Status - Fix players volume based on unconsciousness Medical Feedback - Set volume and radio usage based on status of current players unit Feb 19, 2020
@Whigital
Copy link
Contributor Author

Whigital commented Feb 19, 2020

Toggling unconscious lowers volume and disables the use of ACRE radio without issues.

Not been able to test in MP, but should work the same, considering the code removed from the EH's now run in ace_common_fnc_setVolume instead.

@jonpas jonpas changed the title Medical Feedback - Set volume and radio usage based on status of current players unit Medical Feedback - Set volume and radio usage based current unit Feb 22, 2020
@jonpas jonpas merged commit 1a2487d into acemod:master Feb 22, 2020
@Whigital Whigital deleted the uncon_volume branch February 29, 2020 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-fix Release Notes: **FIXED:**
Projects
Development

Successfully merging this pull request may close these issues.

Medical - setVolume not called on unconscious
3 participants