diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index 23c90b2579..acba4f58ad 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -1,22 +1,26 @@ // #define DEBUG_MODE_FULL #include "script_component.hpp" -[QEGVAR(medical,setUnconscious), LINKFUNC(setUnconscious)] call CBA_fnc_addEventHandler; +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; -if (!hasInterface) exitWith {}; + [QEGVAR(medical,setUnconscious), LINKFUNC(setUnconscious)] call CBA_fnc_addEventHandler; -// Fractures affect base sway, pain makes it worse -["baseline", { - ACE_player getVariable [QEGVAR(medical_engine,aimFracture), 0] -}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); + if (!hasInterface) exitWith {}; -// Max pain = 5x sway -["multiplier", { - 1 + (GET_PAIN_PERCEIVED(ACE_player) * 4) -}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); + // Fractures affect base sway, pain makes it worse + ["baseline", { + ACE_player getVariable [QEGVAR(medical_engine,aimFracture), 0] + }, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); -#ifdef DEBUG_MODE_FULL - call compile preprocessFileLineNumbers QPATHTOF(dev\reportSettings.sqf); - call compile preprocessFileLineNumbers QPATHTOF(dev\watchVariable.sqf); - call compile preprocessFileLineNumbers QPATHTOF(dev\debugDisplay.sqf); -#endif + // Max pain = 5x sway + ["multiplier", { + 1 + (GET_PAIN_PERCEIVED(ACE_player) * 4) + }, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); + + #ifdef DEBUG_MODE_FULL + call compile preprocessFileLineNumbers QPATHTOF(dev\reportSettings.sqf); + call compile preprocessFileLineNumbers QPATHTOF(dev\watchVariable.sqf); + call compile preprocessFileLineNumbers QPATHTOF(dev\debugDisplay.sqf); + #endif +}] call CBA_fnc_addEventHandler; diff --git a/addons/medical/functions/fnc_addDamageToUnit.sqf b/addons/medical/functions/fnc_addDamageToUnit.sqf index e490399c4b..42d43ae5f3 100644 --- a/addons/medical/functions/fnc_addDamageToUnit.sqf +++ b/addons/medical/functions/fnc_addDamageToUnit.sqf @@ -23,6 +23,12 @@ */ // #define DEBUG_TESTRESULTS +if (!EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [LINKFUNC(addDamageToUnit), _this]; +}; + +if !(GETEGVAR(medical,enabled,false)) exitWith {false}; + params [ ["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], diff --git a/addons/medical/functions/fnc_adjustPainLevel.sqf b/addons/medical/functions/fnc_adjustPainLevel.sqf index f5c3d9a35d..ba2250955b 100644 --- a/addons/medical/functions/fnc_adjustPainLevel.sqf +++ b/addons/medical/functions/fnc_adjustPainLevel.sqf @@ -12,12 +12,18 @@ * The new pain level * * Example: - * [guy, 0.5] call ace_medical_fnc_adjustPainLevel + * [player, 0.5] call ace_medical_fnc_adjustPainLevel * * Public: Yes */ -params ["_unit", "_addedPain"]; +if (!EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [LINKFUNC(adjustPainLevel), _this]; +}; + +if !(GETEGVAR(medical,enabled,false)) exitWith {}; + +params [["_unit", objNull, [objNull]], ["_addedPain", 0, [0]]]; if (!local _unit) exitWith { ERROR_1("unit [%1] is not local",_unit); }; diff --git a/addons/medical/functions/fnc_deserializeState.sqf b/addons/medical/functions/fnc_deserializeState.sqf index b7846bf901..24f583d7e9 100644 --- a/addons/medical/functions/fnc_deserializeState.sqf +++ b/addons/medical/functions/fnc_deserializeState.sqf @@ -15,6 +15,13 @@ * * Public: Yes */ + +if (!EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [LINKFUNC(deserializeState), _this]; +}; + +if !(GETEGVAR(medical,enabled,false)) exitWith {}; + params [["_unit", objNull, [objNull]], ["_json", "{}", [""]]]; // Don't run in scheduled environment diff --git a/addons/medical/functions/fnc_serializeState.sqf b/addons/medical/functions/fnc_serializeState.sqf index 67783e85d9..75cc04ff8a 100644 --- a/addons/medical/functions/fnc_serializeState.sqf +++ b/addons/medical/functions/fnc_serializeState.sqf @@ -10,10 +10,17 @@ * Serialized state as JSON string * * Example: - * [player] call ace_medical_fnc_serializeState + * player call ace_medical_fnc_serializeState * * Public: Yes */ + +if (!EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [LINKFUNC(serializeState), _this]; +}; + +if !(GETEGVAR(medical,enabled,false)) exitWith {""}; + params [["_unit", objNull, [objNull]]]; private _state = [] call CBA_fnc_createNamespace; diff --git a/addons/medical/functions/fnc_setUnconscious.sqf b/addons/medical/functions/fnc_setUnconscious.sqf index a1de71c36b..cb3550222e 100644 --- a/addons/medical/functions/fnc_setUnconscious.sqf +++ b/addons/medical/functions/fnc_setUnconscious.sqf @@ -6,8 +6,8 @@ * Arguments: * 0: The unit that will be put in an unconscious state * 1: Set unconsciouns (default: true) - * 2: Minimum unconscious time (set to 0 to ignore) (default: 0) - * 3: Force wakeup at given time if vitals are stable (default: false) + * 2: Minimum unconscious time (set to 0 to ignore) (default: 0) + * 3: Force wakeup at given time if vitals are stable (default: false) * * Return Value: * Success? @@ -19,11 +19,12 @@ * Public: Yes */ -// only run this after the settings are initialized -if !(EGVAR(common,settingsInitFinished)) exitWith { - EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(setUnconscious), _this]; +if (!EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [LINKFUNC(setUnconscious), _this]; }; +if !(GETEGVAR(medical,enabled,false)) exitWith {}; + params [["_unit", objNull, [objNull]], ["_knockOut", true, [false]], ["_minWaitingTime", 0, [0]], ["_forcedWakup", false, [false]]]; TRACE_4("setUnconscious",_unit,_knockOut,_minWaitingTime,_forcedWakup); diff --git a/addons/medical_ai/XEH_postInit.sqf b/addons/medical_ai/XEH_postInit.sqf index 0b225c7f0b..97b4567196 100644 --- a/addons/medical_ai/XEH_postInit.sqf +++ b/addons/medical_ai/XEH_postInit.sqf @@ -1,8 +1,9 @@ #include "script_component.hpp" ["CBA_settingsInitialized", { - TRACE_1("settingsInitialized",GVAR(enabledFor)); - if (GVAR(enabledFor) == 0) exitWith {}; // 0: disabled + TRACE_2("settingsInitialized",GVAR(enabledFor),GETEGVAR(medical,enabled,false)); + + if (GVAR(enabledFor) == 0 || {!(GETEGVAR(medical,enabled,false))}) exitWith {}; // 0: disabled if ((GVAR(enabledFor) == 1) && {!isServer} && {hasInterface}) exitWith {}; // 1: Don't Run on non-hc Clients ["ace_firedNonPlayer", { @@ -20,5 +21,4 @@ }] call CBA_fnc_addClassEventHandler; #include "stateMachine.inc.sqf" - }] call CBA_fnc_addEventHandler; diff --git a/addons/medical_blood/XEH_postInit.sqf b/addons/medical_blood/XEH_postInit.sqf index b08921b441..fe64fffc54 100644 --- a/addons/medical_blood/XEH_postInit.sqf +++ b/addons/medical_blood/XEH_postInit.sqf @@ -1,25 +1,29 @@ #include "script_component.hpp" -// To support public API regardless of component settings -[QGVAR(spurt), LINKFUNC(spurt)] call CBA_fnc_addEventHandler; +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; -if (isServer) then { - GVAR(bloodDrops) = []; + // To support public API regardless of component settings + [QGVAR(spurt), LINKFUNC(spurt)] call CBA_fnc_addEventHandler; - [QGVAR(bloodDropCreated), { - params ["_bloodDrop", "_source"]; + if (isServer) then { + GVAR(bloodDrops) = []; - // Add to created queue with format: [expire time, blood object, source unit] - private _index = GVAR(bloodDrops) pushBack [CBA_missionTime + GVAR(bloodLifetime), _bloodDrop, _source]; + [QGVAR(bloodDropCreated), { + params ["_bloodDrop", "_source"]; - if (count GVAR(bloodDrops) >= GVAR(maxBloodObjects)) then { - (GVAR(bloodDrops) deleteAt 0) params ["", "_deletedBloodDrop"]; - deleteVehicle _deletedBloodDrop; - }; + // Add to created queue with format: [expire time, blood object, source unit] + private _index = GVAR(bloodDrops) pushBack [CBA_missionTime + GVAR(bloodLifetime), _bloodDrop, _source]; - // Start the cleanup loop - if (_index == 0) then { - [LINKFUNC(cleanupLoop), [], GVAR(bloodLifetime)] call CBA_fnc_waitAndExecute; - }; - }] call CBA_fnc_addEventHandler; -}; + if (count GVAR(bloodDrops) >= GVAR(maxBloodObjects)) then { + (GVAR(bloodDrops) deleteAt 0) params ["", "_deletedBloodDrop"]; + deleteVehicle _deletedBloodDrop; + }; + + // Start the cleanup loop + if (_index == 0) then { + [LINKFUNC(cleanupLoop), [], GVAR(bloodLifetime)] call CBA_fnc_waitAndExecute; + }; + }] call CBA_fnc_addEventHandler; + }; +}] call CBA_fnc_addEventHandler; diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index cd25dee2e0..e122b7aad0 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -1,112 +1,116 @@ #include "script_component.hpp" -[QGVAR(updateDamageEffects), LINKFUNC(updateDamageEffects)] call CBA_fnc_addEventHandler; +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; -["unit", { - params ["_new"]; - [_new] call FUNC(updateDamageEffects); // Run on new controlled unit to update QGVAR(aimFracture) -}, true] call CBA_fnc_addPlayerEventHandler; + [QGVAR(updateDamageEffects), LINKFUNC(updateDamageEffects)] call CBA_fnc_addEventHandler; -["CAManBase", "init", { - params ["_unit"]; + ["unit", { + params ["_new"]; + [_new] call FUNC(updateDamageEffects); // Run on new controlled unit to update QGVAR(aimFracture) + }, true] call CBA_fnc_addPlayerEventHandler; - if (unitIsUAV _unit) exitWith {TRACE_1("ignore UAV AI",typeOf _unit);}; - if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);}; + ["CAManBase", "init", { + params ["_unit"]; - private _allHitPoints = getAllHitPointsDamage _unit param [0, []]; - if ((GVAR(customHitpoints) arrayIntersect _allHitPoints) isNotEqualTo GVAR(customHitpoints)) exitWith { - ERROR_1("Bad hitpoints for unit type ""%1""",typeOf _unit); + if (unitIsUAV _unit) exitWith {TRACE_1("ignore UAV AI",typeOf _unit);}; + if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);}; + + private _allHitPoints = getAllHitPointsDamage _unit param [0, []]; + if ((GVAR(customHitpoints) arrayIntersect _allHitPoints) isNotEqualTo GVAR(customHitpoints)) exitWith { + ERROR_1("Bad hitpoints for unit type ""%1""",typeOf _unit); + }; + + // Calling this function inside curly brackets allows the usage of + // "exitWith", which would be broken with "HandleDamage" otherwise. + _unit setVariable [ + QEGVAR(medical,HandleDamageEHID), + _unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}] + ]; + + _unit addEventHandler ["HandleHeal", { + params ["_injured", "_healer"]; + + // Replace the items so that the unit can't heal + _healer call EFUNC(common,replaceRegisteredItems); + + AISFinishHeal [_injured, _healer, true]; + + // Set animation to what it was before starting the healing animation + [{"dnon_medic" in animationState (_this select 0)}, { + [_this select 0, _this select 1, 2] call EFUNC(common,doAnimation); + }, [_healer, _healer call EFUNC(common,getDefaultAnim)], 5] call CBA_fnc_waitUntilAndExecute; + }]; + }, nil, [IGNORE_BASE_UAVPILOTS], true] call CBA_fnc_addClassEventHandler; + + if !(["ace_medical_treatment"] call EFUNC(common,isModLoaded)) then { + [TYPE_FIRST_AID_KIT, ""] call EFUNC(common,registerItemReplacement); + [TYPE_MEDIKIT, ""] call EFUNC(common,registerItemReplacement); }; - // Calling this function inside curly brackets allows the usage of - // "exitWith", which would be broken with "HandleDamage" otherwise. - _unit setVariable [ - QEGVAR(medical,HandleDamageEHID), - _unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}] - ]; + #ifdef DEBUG_MODE_FULL + [QEGVAR(medical,woundReceived), { + params ["_unit", "_damages", "_shooter", "_ammo"]; + TRACE_4("wound",_unit,_damages,_shooter,_ammo); + //systemChat str _this; + }] call CBA_fnc_addEventHandler; + #endif - _unit addEventHandler ["HandleHeal", { - params ["_injured", "_healer"]; + // this handles moving units into vehicles via load functions or zeus + // needed, because the vanilla INCAPACITATED state does not handle vehicles + ["CAManBase", "GetInMan", { + params ["_unit", "", "_vehicle"]; - // Replace the items so that the unit can't heal - _healer call EFUNC(common,replaceRegisteredItems); + if (local _unit && {lifeState _unit == "INCAPACITATED"}) then { + [_unit, true] call FUNC(setUnconsciousAnim); + }; - AISFinishHeal [_injured, _healer, true]; - - // Set animation to what it was before starting the healing animation - [{"dnon_medic" in animationState (_this select 0)}, { - [_this select 0, _this select 1, 2] call EFUNC(common,doAnimation); - }, [_healer, _healer call EFUNC(common,getDefaultAnim)], 5] call CBA_fnc_waitUntilAndExecute; - }]; -}, nil, [IGNORE_BASE_UAVPILOTS], true] call CBA_fnc_addClassEventHandler; - -if !(["ace_medical_treatment"] call EFUNC(common,isModLoaded)) then { - [TYPE_FIRST_AID_KIT, ""] call EFUNC(common,registerItemReplacement); - [TYPE_MEDIKIT, ""] call EFUNC(common,registerItemReplacement); -}; - -#ifdef DEBUG_MODE_FULL -[QEGVAR(medical,woundReceived), { - params ["_unit", "_damages", "_shooter", "_ammo"]; - TRACE_4("wound",_unit,_damages,_shooter,_ammo); - //systemChat str _this; -}] call CBA_fnc_addEventHandler; -#endif - -// this handles moving units into vehicles via load functions or zeus -// needed, because the vanilla INCAPACITATED state does not handle vehicles -["CAManBase", "GetInMan", { - params ["_unit", "", "_vehicle"]; - - if (local _unit && {lifeState _unit == "INCAPACITATED"}) then { - [_unit, true] call FUNC(setUnconsciousAnim); - }; - - if (local _vehicle) then { - [_unit] call FUNC(lockUnconsciousSeat); - }; -}] call CBA_fnc_addClassEventHandler; - -["CAManBase", "GetOutMan", { - params ["_unit", "", "_vehicle"]; - - if (local _vehicle) then { - [_unit] call FUNC(unlockUnconsciousSeat); - }; -}] call CBA_fnc_addClassEventHandler; - -// Fixes units being stuck in unconscious animation when being knocked over by a PhysX object -["CAManBase", "AnimDone", { - params ["_unit", "_anim"]; - if (local _unit && {_anim find QUNCON_ANIM(face) != -1 && {lifeState _unit != "INCAPACITATED"}}) then { - [_unit, false] call FUNC(setUnconsciousAnim); - }; -}] call CBA_fnc_addClassEventHandler; - -["ace_unconscious", { - params ["_unit", "_unconscious"]; - TRACE_3("unit uncon",_unit,objectParent _unit,local _unit); - if (!isNull objectParent _unit && {local objectParent _unit}) then { - if (_unconscious) then { + if (local _vehicle) then { [_unit] call FUNC(lockUnconsciousSeat); - } else { + }; + }] call CBA_fnc_addClassEventHandler; + + ["CAManBase", "GetOutMan", { + params ["_unit", "", "_vehicle"]; + + if (local _vehicle) then { [_unit] call FUNC(unlockUnconsciousSeat); }; - }; -}] call CBA_fnc_addEventHandler; + }] call CBA_fnc_addClassEventHandler; -["ace_killed", { // global event - params ["_unit"]; - TRACE_3("unit Killed",_unit,objectParent _unit,local _unit); - if (!isNull objectParent _unit && {local objectParent _unit}) exitWith { - [_unit] call FUNC(lockUnconsciousSeat); - }; -}] call CBA_fnc_addEventHandler; + // Fixes units being stuck in unconscious animation when being knocked over by a PhysX object + ["CAManBase", "AnimDone", { + params ["_unit", "_anim"]; + if (local _unit && {_anim find QUNCON_ANIM(face) != -1 && {lifeState _unit != "INCAPACITATED"}}) then { + [_unit, false] call FUNC(setUnconsciousAnim); + }; + }] call CBA_fnc_addClassEventHandler; -["CAManBase", "Deleted", { - params ["_unit"]; - TRACE_3("unit deleted",_unit,objectParent _unit,local _unit); - if ((!isNull objectParent _unit) && {local objectParent _unit}) then { - [_unit] call FUNC(unlockUnconsciousSeat); - }; -}, true, []] call CBA_fnc_addClassEventHandler; + ["ace_unconscious", { + params ["_unit", "_unconscious"]; + TRACE_3("unit uncon",_unit,objectParent _unit,local _unit); + if (!isNull objectParent _unit && {local objectParent _unit}) then { + if (_unconscious) then { + [_unit] call FUNC(lockUnconsciousSeat); + } else { + [_unit] call FUNC(unlockUnconsciousSeat); + }; + }; + }] call CBA_fnc_addEventHandler; + + ["ace_killed", { // global event + params ["_unit"]; + TRACE_3("unit Killed",_unit,objectParent _unit,local _unit); + if (!isNull objectParent _unit && {local objectParent _unit}) exitWith { + [_unit] call FUNC(lockUnconsciousSeat); + }; + }] call CBA_fnc_addEventHandler; + + ["CAManBase", "Deleted", { + params ["_unit"]; + TRACE_3("unit deleted",_unit,objectParent _unit,local _unit); + if ((!isNull objectParent _unit) && {local objectParent _unit}) then { + [_unit] call FUNC(unlockUnconsciousSeat); + }; + }, true, []] call CBA_fnc_addClassEventHandler; +}] call CBA_fnc_addEventHandler; diff --git a/addons/medical_feedback/XEH_postInit.sqf b/addons/medical_feedback/XEH_postInit.sqf index f01394e919..1200998739 100644 --- a/addons/medical_feedback/XEH_postInit.sqf +++ b/addons/medical_feedback/XEH_postInit.sqf @@ -1,141 +1,145 @@ #include "script_component.hpp" -[QEGVAR(medical,injured), { - params ["_unit", "_painLevel"]; - [_unit, "hit", PAIN_TO_SCREAM(_painLevel)] call FUNC(playInjuredSound); +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; - if (hasInterface && {_unit == ace_player}) then { + [QEGVAR(medical,injured), { + params ["_unit", "_painLevel"]; + [_unit, "hit", PAIN_TO_SCREAM(_painLevel)] call FUNC(playInjuredSound); + + if (hasInterface && {_unit == ace_player}) then { + [true] call FUNC(handleEffects); + }; + }] call CBA_fnc_addEventHandler; + + [QEGVAR(medical,moan), { + params ["_unit", "_painLevel"]; + [_unit, "moan", PAIN_TO_MOAN(_painLevel)] call FUNC(playInjuredSound); + }] call CBA_fnc_addEventHandler; + + if (!hasInterface) exitWith {}; + + [QEGVAR(medical,fracture), { + params ["_unit"]; + if (_unit == ACE_player) then { + playSound SND_FRACTURE; + }; + }] call CBA_fnc_addEventHandler; + + GVAR(nextFadeIn) = 0; + GVAR(heartBeatEffectRunning) = false; + GVAR(lastHeartBeatSound) = 0; + GVAR(bloodTickCounter) = 0; + + [false] call FUNC(initEffects); + [true] call FUNC(handleEffects); + [LINKFUNC(handleEffects), 1, false] call CBA_fnc_addPerFrameHandler; + + ["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"; + }; + + [!_unconscious, _unit] call EFUNC(common,setVolume); + + // Greatly reduce player's hearing ability while unconscious (affects radio addons) + private _volume = missionNamespace getVariable [QEGVAR(hearing,unconsciousnessVolume), VOL_UNCONSCIOUS]; + [QUOTE(ADDON), _volume, _unconscious] call EFUNC(common,setHearingCapability); + + [_unconscious, 1] call FUNC(effectUnconscious); [true] call FUNC(handleEffects); - }; -}] call CBA_fnc_addEventHandler; + ["unconscious", _unconscious] call EFUNC(common,setDisableUserInputStatus); + }] call CBA_fnc_addEventHandler; -[QEGVAR(medical,moan), { - params ["_unit", "_painLevel"]; - [_unit, "moan", PAIN_TO_MOAN(_painLevel)] call FUNC(playInjuredSound); -}] call CBA_fnc_addEventHandler; + // Reset volume upon death for spectators + [QEGVAR(medical,death), { + params ["_unit"]; -if (!hasInterface) exitWith {}; - -[QEGVAR(medical,fracture), { - params ["_unit"]; - if (_unit == ACE_player) then { - playSound SND_FRACTURE; - }; -}] call CBA_fnc_addEventHandler; - -GVAR(nextFadeIn) = 0; -GVAR(heartBeatEffectRunning) = false; -GVAR(lastHeartBeatSound) = 0; -GVAR(bloodTickCounter) = 0; - -[false] call FUNC(initEffects); -[true] call FUNC(handleEffects); -[LINKFUNC(handleEffects), 1, false] call CBA_fnc_addPerFrameHandler; - -["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"; - }; - - [!_unconscious, _unit] call EFUNC(common,setVolume); - - // Greatly reduce player's hearing ability while unconscious (affects radio addons) - private _volume = missionNamespace getVariable [QEGVAR(hearing,unconsciousnessVolume), VOL_UNCONSCIOUS]; - [QUOTE(ADDON), _volume, _unconscious] call EFUNC(common,setHearingCapability); - - [_unconscious, 1] call FUNC(effectUnconscious); - [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 {}; - // Players always able to hear for any systems that might run while dead (e.g. spectator) - [true, _unit] call EFUNC(common,setVolume); - - [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); - - [!_status, _new] call EFUNC(common,setVolume); - - private _volume = missionNamespace getVariable [QEGVAR(hearing,unconsciousnessVolume), VOL_UNCONSCIOUS]; - [QUOTE(ADDON), _volume, _status] call EFUNC(common,setHearingCapability); - [true] call FUNC(handleEffects); - ["unconscious", _status] call EFUNC(common,setDisableUserInputStatus); -}] call CBA_fnc_addPlayerEventHandler; - -// Update effects for featureCamera (curator, arsenal, etc) -["featureCamera", { - params ["_unit", "_newCamera"]; - - [true] call FUNC(handleEffects); - - private _volume = missionNamespace getVariable [QEGVAR(hearing,unconsciousnessVolume), VOL_UNCONSCIOUS]; - - if (_newCamera == "") then { // switched back to player view - private _status = IS_UNCONSCIOUS(_unit); - [!_status, _unit] call EFUNC(common,setVolume); - [QUOTE(ADDON), _volume, _status] call EFUNC(common,setHearingCapability); - ["unconscious", _status] call EFUNC(common,setDisableUserInputStatus); - } else { // camera view + if (_unit != ACE_player) exitWith {}; + // Players always able to hear for any systems that might run while dead (e.g. spectator) [true, _unit] call EFUNC(common,setVolume); + [QUOTE(ADDON), 1, false] call EFUNC(common,setHearingCapability); - ["unconscious", false] call EFUNC(common,setDisableUserInputStatus); - }; -}] call CBA_fnc_addPlayerEventHandler; + }] call CBA_fnc_addEventHandler; -// Forced say3D -[QGVAR(forceSay3D), { - params ["_unit", "_sound", "_distance"]; + // Update effects to match new unit's current status (this also handles respawn) + ["unit", { + params ["_new"]; + private _status = IS_UNCONSCIOUS(_new); - if (ACE_player distance _unit > _distance) exitWith {}; + [!_status, _new] call EFUNC(common,setVolume); - if (isNull objectParent _unit) then { - // say3D waits for the previous sound to finish, so use a dummy instead - private _dummy = "#dynamicsound" createVehicleLocal [0, 0, 0]; - _dummy attachTo [_unit, [0, 0, 0], "camera"]; - _dummy say3D [_sound, _distance, 1, false]; + private _volume = missionNamespace getVariable [QEGVAR(hearing,unconsciousnessVolume), VOL_UNCONSCIOUS]; + [QUOTE(ADDON), _volume, _status] call EFUNC(common,setHearingCapability); + [true] call FUNC(handleEffects); + ["unconscious", _status] call EFUNC(common,setDisableUserInputStatus); + }] call CBA_fnc_addPlayerEventHandler; - [{ - detach _this; - deleteVehicle _this; - }, _dummy, 5] call CBA_fnc_waitAndExecute; - } else { - // Fallback: attachTo doesn't work within vehicles - _unit say3D [_sound, _distance, 1, false]; - }; + // Update effects for featureCamera (curator, arsenal, etc) + ["featureCamera", { + params ["_unit", "_newCamera"]; + + [true] call FUNC(handleEffects); + + private _volume = missionNamespace getVariable [QEGVAR(hearing,unconsciousnessVolume), VOL_UNCONSCIOUS]; + + if (_newCamera == "") then { // switched back to player view + private _status = IS_UNCONSCIOUS(_unit); + [!_status, _unit] call EFUNC(common,setVolume); + [QUOTE(ADDON), _volume, _status] call EFUNC(common,setHearingCapability); + ["unconscious", _status] call EFUNC(common,setDisableUserInputStatus); + } else { // camera view + [true, _unit] call EFUNC(common,setVolume); + [QUOTE(ADDON), 1, false] call EFUNC(common,setHearingCapability); + ["unconscious", false] call EFUNC(common,setDisableUserInputStatus); + }; + }] call CBA_fnc_addPlayerEventHandler; + + // Forced say3D + [QGVAR(forceSay3D), { + params ["_unit", "_sound", "_distance"]; + + if (ACE_player distance _unit > _distance) exitWith {}; + + if (isNull objectParent _unit) then { + // say3D waits for the previous sound to finish, so use a dummy instead + private _dummy = "#dynamicsound" createVehicleLocal [0, 0, 0]; + _dummy attachTo [_unit, [0, 0, 0], "camera"]; + _dummy say3D [_sound, _distance, 1, false]; + + [{ + detach _this; + deleteVehicle _this; + }, _dummy, 5] call CBA_fnc_waitAndExecute; + } else { + // Fallback: attachTo doesn't work within vehicles + _unit say3D [_sound, _distance, 1, false]; + }; + }] call CBA_fnc_addEventHandler; + + // Kill vanilla bleeding feedback effects. + #ifdef DISABLE_VANILLA_DAMAGE_EFFECTS + TRACE_1("disabling vanilla bleeding feedback effects",_this); + [{ + {isNil _x} count [ + "BIS_fnc_feedback_damageCC", + "BIS_fnc_feedback_damageRadialBlur", + "BIS_fnc_feedback_damageBlur" + ] == 0 + }, { + { + ppEffectDestroy _x; + } forEach [ + BIS_fnc_feedback_damageCC, + BIS_fnc_feedback_damageRadialBlur, + BIS_fnc_feedback_damageBlur + ]; + }] call CBA_fnc_waitUntilAndExecute; + #endif }] call CBA_fnc_addEventHandler; - -// Kill vanilla bleeding feedback effects. -#ifdef DISABLE_VANILLA_DAMAGE_EFFECTS -TRACE_1("disabling vanilla bleeding feedback effects",_this); -[{ - {isNil _x} count [ - "BIS_fnc_feedback_damageCC", - "BIS_fnc_feedback_damageRadialBlur", - "BIS_fnc_feedback_damageBlur" - ] == 0 -}, { - { - ppEffectDestroy _x; - } forEach [ - BIS_fnc_feedback_damageCC, - BIS_fnc_feedback_damageRadialBlur, - BIS_fnc_feedback_damageBlur - ]; -}] call CBA_fnc_waitUntilAndExecute; -#endif diff --git a/addons/medical_gui/CfgVehicles.hpp b/addons/medical_gui/CfgVehicles.hpp index 502039325a..3e4a67ec4f 100644 --- a/addons/medical_gui/CfgVehicles.hpp +++ b/addons/medical_gui/CfgVehicles.hpp @@ -4,7 +4,7 @@ class CfgVehicles { class ACE_SelfActions { class ACE_Medical { displayName = CSTRING(Medical); - condition = QGVAR(enableSelfActions); + condition = QUOTE(missionNamespace getVariable [ARR_2(QQEGVAR(medical,enabled),false)] && GVAR(enableSelfActions)); exceptions[] = {"isNotInside", "isNotSitting", "isNotSwimming"}; statement = QUOTE([ARR_2(_target,-1)] call FUNC(displayPatientInformation)); runOnHover = 1; @@ -23,7 +23,7 @@ class CfgVehicles { }; }; class ACE_Actions { - #define ACTION_CONDITION condition = QUOTE(GVAR(enableActions) == 0); + #define ACTION_CONDITION condition = QUOTE(missionNamespace getVariable [ARR_2(QQEGVAR(medical,enabled),false)] && GVAR(enableActions) == 0); #include "InteractionBodyParts.hpp" #undef ACTION_CONDITION class ACE_MainActions { @@ -38,7 +38,7 @@ class CfgVehicles { }; class ACE_Medical_Radial { displayName = CSTRING(Medical); - condition = QUOTE((GVAR(enableActions) == 1 || {GVAR(enableActions) != 2 && {!isNull objectParent _target && {objectParent _target isEqualTo objectParent _player}}})); + condition = QUOTE(missionNamespace getVariable [ARR_2(QQEGVAR(medical,enabled),false)] && (GVAR(enableActions) == 1 || {GVAR(enableActions) != 2 && {!isNull objectParent _target && {objectParent _target isEqualTo objectParent _player}}})); exceptions[] = {"isNotInside", "isNotSitting"}; statement = QUOTE([ARR_2(_target,-1)] call FUNC(displayPatientInformation)); runOnHover = 1; @@ -49,7 +49,7 @@ class CfgVehicles { }; class ACE_LoadPatient { displayName = CSTRING(LoadPatient); - condition = QUOTE(_target getVariable [ARR_2('ACE_isUnconscious',false)] && {alive _target} && {isNull objectParent _target} && {(_target call EFUNC(common,nearestVehiclesFreeSeat)) isNotEqualTo []}); + condition = QUOTE(missionNamespace getVariable [ARR_2(QQEGVAR(medical,enabled),false)] && {_target getVariable [ARR_2('ACE_isUnconscious',false)]} && {alive _target} && {isNull objectParent _target} && {(_target call EFUNC(common,nearestVehiclesFreeSeat)) isNotEqualTo []}); exceptions[] = {"isNotDragging", "isNotCarrying"}; statement = QUOTE([ARR_2(_player,_target)] call EFUNC(medical_treatment,loadUnit)); icon = QPATHTOF(ui\cross.paa); diff --git a/addons/medical_gui/XEH_postInit.sqf b/addons/medical_gui/XEH_postInit.sqf index 2b7fb8ce52..841291b7a7 100644 --- a/addons/medical_gui/XEH_postInit.sqf +++ b/addons/medical_gui/XEH_postInit.sqf @@ -2,115 +2,63 @@ if (!hasInterface) exitWith {}; -GVAR(target) = objNull; -GVAR(previousTarget) = objNull; -GVAR(selectedBodyPart) = 0; -GVAR(selectedCategory) = "triage"; +#include "initKeybinds.inc.sqf" -GVAR(lastOpenedOn) = -1; -GVAR(pendingReopen) = false; +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; + + GVAR(target) = objNull; + GVAR(previousTarget) = objNull; + GVAR(selectedBodyPart) = 0; + GVAR(selectedCategory) = "triage"; -GVAR(menuPFH) = -1; + GVAR(lastOpenedOn) = -1; + GVAR(pendingReopen) = false; -GVAR(peekLastOpenedOn) = -1; -GVAR(peekOnHitLastOpenedOn) = -1; + GVAR(menuPFH) = -1; -GVAR(selfInteractionActions) = []; -[] call FUNC(addTreatmentActions); -[] call FUNC(collectActions); + GVAR(peekLastOpenedOn) = -1; + GVAR(peekOnHitLastOpenedOn) = -1; -[QEGVAR(interact_menu,newControllableObject), { - params ["_type"]; // string of the object's classname - if !(_type isKindOf "CAManBase") exitWith {}; - { - _x set [0, _type]; - _x call EFUNC(interact_menu,addActionToClass); - } forEach GVAR(selfInteractionActions); -}] call CBA_fnc_addEventHandler; + GVAR(selfInteractionActions) = []; + [] call FUNC(addTreatmentActions); + [] call FUNC(collectActions); -["ace_treatmentSucceded", { - if (GVAR(openAfterTreatment) && {GVAR(pendingReopen)}) then { - GVAR(pendingReopen) = false; - [FUNC(openMenu), GVAR(target)] call CBA_fnc_execNextFrame; - }; -}] call CBA_fnc_addEventHandler; + [QEGVAR(interact_menu,newControllableObject), { + params ["_type"]; // string of the object's classname + if !(_type isKindOf "CAManBase") exitWith {}; + { + _x set [0, _type]; + _x call EFUNC(interact_menu,addActionToClass); + } forEach GVAR(selfInteractionActions); + }] call CBA_fnc_addEventHandler; -["ACE3 Common", QGVAR(openMedicalMenuKey), localize LSTRING(OpenMedicalMenu), { - // Get target (cursorTarget, cursorObject, and lineIntersectsSurfaces along camera to maxDistance), if not valid then target is ACE_player - TRACE_3("Open menu key",cursorTarget,cursorObject,ACE_player); - private _target = cursorTarget; - if !(_target isKindOf "CAManBase" && {[ACE_player, _target] call FUNC(canOpenMenu)}) then { - _target = cursorObject; - if !(_target isKindOf "CAManBase" && {[ACE_player, _target] call FUNC(canOpenMenu)}) then { - private _start = AGLToASL positionCameraToWorld [0, 0, 0]; - private _end = AGLToASL positionCameraToWorld [0, 0, GVAR(maxDistance)]; - private _intersections = lineIntersectsSurfaces [_start, _end, ACE_player, objNull, true, -1, "FIRE"]; - { - _x params ["", "", "_intersectObject"]; - // Only look "through" player and player's vehicle - if (!(_intersectObject isKindOf "CAManBase") && {_intersectObject != vehicle ACE_player}) exitWith {}; - if (_intersectObject != ACE_player && {_intersectObject isKindOf "CAManBase" && {[ACE_player, _intersectObject] call FUNC(canOpenMenu)}}) exitWith { - _target =_intersectObject - }; - } forEach _intersections; - if (!(_target isKindOf "CAManBase") || {!([ACE_player, _target] call FUNC(canOpenMenu))}) then { - _target = ACE_player; - }; + ["ace_treatmentSucceded", { + if (GVAR(openAfterTreatment) && {GVAR(pendingReopen)}) then { + GVAR(pendingReopen) = false; + [FUNC(openMenu), GVAR(target)] call CBA_fnc_execNextFrame; }; - }; + }] call CBA_fnc_addEventHandler; - // Check conditions: canInteract and canOpenMenu - if !([ACE_player, _target, ["isNotInside", "isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false}; - if !([ACE_player, _target] call FUNC(canOpenMenu)) exitWith {false}; + // Close patient information display when interaction menu is closed + ["ace_interactMenuClosed", { + QGVAR(RscPatientInfo) cutFadeOut 0.3; + }] call CBA_fnc_addEventHandler; - // Statement - [_target] call FUNC(openMenu); - false -}, { - // Close menu if enough time passed from opening - if (CBA_missionTime - GVAR(lastOpenedOn) > 0.5) exitWith { - [objNull] call FUNC(openMenu); - }; - false -}, [DIK_H, [false, false, false]], false, 0] call CBA_fnc_addKeybind; + [QEGVAR(medical,woundReceived), { + params ["_unit", "_allDamages", ""]; + if !(GVAR(peekMedicalOnHit) && {_unit == ACE_player}) exitWith {}; -["ACE3 Common", QGVAR(peekMedicalInfoKey), localize LSTRING(PeekMedicalInfo), -{ - // Conditions: canInteract - if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false}; + private _bodypart = toLowerANSI (_allDamages select 0 select 1); + private _bodypartIndex = ALL_BODY_PARTS find _bodypart; - // Statement - [ACE_player, -1] call FUNC(displayPatientInformation); - false -}, { - if (CBA_missionTime - GVAR(peekLastOpenedOn) > GVAR(peekMedicalInfoReleaseDelay)) then { - [{ - CBA_missionTime - GVAR(peekLastOpenedOn) > GVAR(peekMedicalInfoReleaseDelay) - }, {QGVAR(RscPatientInfo) cutFadeOut 0.3}] call CBA_fnc_waitUntilAndExecute; - }; - GVAR(peekLastOpenedOn) = CBA_missionTime; - false -}, [DIK_H, [false, true, false]], false, 0] call CBA_fnc_addKeybind; + [ACE_player, _bodypartIndex] call FUNC(displayPatientInformation); - -// Close patient information display when interaction menu is closed -["ace_interactMenuClosed", { - QGVAR(RscPatientInfo) cutFadeOut 0.3; -}] call CBA_fnc_addEventHandler; - -[QEGVAR(medical,woundReceived), { - params ["_unit", "_allDamages", ""]; - if !(GVAR(peekMedicalOnHit) && {_unit == ACE_player}) exitWith {}; - - private _bodypart = toLowerANSI (_allDamages select 0 select 1); - private _bodypartIndex = ALL_BODY_PARTS find _bodypart; - - [ACE_player, _bodypartIndex] call FUNC(displayPatientInformation); - - if (CBA_missionTime - GVAR(peekOnHitLastOpenedOn) > GVAR(peekMedicalOnHitDuration)) then { - [{ - CBA_missionTime - GVAR(peekOnHitLastOpenedOn) > GVAR(peekMedicalOnHitDuration) - }, {QGVAR(RscPatientInfo) cutFadeOut 0.3}] call CBA_fnc_waitUntilAndExecute; - }; - GVAR(peekOnHitLastOpenedOn) = CBA_missionTime; + if (CBA_missionTime - GVAR(peekOnHitLastOpenedOn) > GVAR(peekMedicalOnHitDuration)) then { + [{ + CBA_missionTime - GVAR(peekOnHitLastOpenedOn) > GVAR(peekMedicalOnHitDuration) + }, {QGVAR(RscPatientInfo) cutFadeOut 0.3}] call CBA_fnc_waitUntilAndExecute; + }; + GVAR(peekOnHitLastOpenedOn) = CBA_missionTime; + }] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler; diff --git a/addons/medical_gui/functions/fnc_canOpenMenu.sqf b/addons/medical_gui/functions/fnc_canOpenMenu.sqf index fc2ac3879e..45fd8f79df 100644 --- a/addons/medical_gui/functions/fnc_canOpenMenu.sqf +++ b/addons/medical_gui/functions/fnc_canOpenMenu.sqf @@ -16,6 +16,8 @@ * Public: No */ +if !(GETEGVAR(medical,enabled,false)) exitWith {false}; + params ["_player", "_target"]; // If in Zeus diff --git a/addons/medical_gui/functions/fnc_modifyActionTriageLevel.sqf b/addons/medical_gui/functions/fnc_modifyActionTriageLevel.sqf index b8cca898f2..9ac0d61c1b 100644 --- a/addons/medical_gui/functions/fnc_modifyActionTriageLevel.sqf +++ b/addons/medical_gui/functions/fnc_modifyActionTriageLevel.sqf @@ -18,7 +18,10 @@ * Public: No */ +if !(GETEGVAR(medical,enabled,false)) exitWith {}; + params ["_target", "_player", "", "_actionData"]; + if ( GVAR(interactionMenuShowTriage) == 1 // Anyone || {GVAR(interactionMenuShowTriage) == 2 && {[_player] call EFUNC(medical_treatment,isMedic)}} // Medics & Doctors diff --git a/addons/medical_gui/initKeybinds.inc.sqf b/addons/medical_gui/initKeybinds.inc.sqf new file mode 100644 index 0000000000..5d5528c59c --- /dev/null +++ b/addons/medical_gui/initKeybinds.inc.sqf @@ -0,0 +1,56 @@ +["ACE3 Common", QGVAR(openMedicalMenuKey), LLSTRING(OpenMedicalMenu), { + // Get target (cursorTarget, cursorObject, and lineIntersectsSurfaces along camera to maxDistance), if not valid then target is ACE_player + TRACE_3("Open menu key",cursorTarget,cursorObject,ACE_player); + private _target = cursorTarget; + if !(_target isKindOf "CAManBase" && {[ACE_player, _target] call FUNC(canOpenMenu)}) then { + _target = cursorObject; + if !(_target isKindOf "CAManBase" && {[ACE_player, _target] call FUNC(canOpenMenu)}) then { + private _start = AGLToASL positionCameraToWorld [0, 0, 0]; + private _end = AGLToASL positionCameraToWorld [0, 0, GVAR(maxDistance)]; + private _intersections = lineIntersectsSurfaces [_start, _end, ACE_player, objNull, true, -1, "FIRE"]; + { + _x params ["", "", "_intersectObject"]; + // Only look "through" player and player's vehicle + if (!(_intersectObject isKindOf "CAManBase") && {_intersectObject != vehicle ACE_player}) exitWith {}; + if (_intersectObject != ACE_player && {_intersectObject isKindOf "CAManBase" && {[ACE_player, _intersectObject] call FUNC(canOpenMenu)}}) exitWith { + _target = _intersectObject + }; + } forEach _intersections; + if (!(_target isKindOf "CAManBase") || {!([ACE_player, _target] call FUNC(canOpenMenu))}) then { + _target = ACE_player; + }; + }; + }; + + // Check conditions: canInteract and canOpenMenu + if !([ACE_player, _target, ["isNotInside", "isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false}; + if !([ACE_player, _target] call FUNC(canOpenMenu)) exitWith {false}; + + // Statement + [_target] call FUNC(openMenu); + false +}, { + // Close menu if enough time passed from opening + if (CBA_missionTime - GVAR(lastOpenedOn) > 0.5) exitWith { + [objNull] call FUNC(openMenu); + }; +}, [DIK_H, [false, false, false]], false, 0] call CBA_fnc_addKeybind; + +["ACE3 Common", QGVAR(peekMedicalInfoKey), localize LSTRING(PeekMedicalInfo), +{ + if !(GETEGVAR(medical,enabled,false)) exitWith {}; + + // Conditions: canInteract + if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false}; + + // Statement + [ACE_player, -1] call FUNC(displayPatientInformation); + false +}, { + if (CBA_missionTime - GVAR(peekLastOpenedOn) > GVAR(peekMedicalInfoReleaseDelay)) then { + [{ + CBA_missionTime - GVAR(peekLastOpenedOn) > GVAR(peekMedicalInfoReleaseDelay) + }, {QGVAR(RscPatientInfo) cutFadeOut 0.3}] call CBA_fnc_waitUntilAndExecute; + }; + GVAR(peekLastOpenedOn) = CBA_missionTime; +}, [DIK_H, [false, true, false]], false, 0] call CBA_fnc_addKeybind; diff --git a/addons/medical_statemachine/XEH_postInit.sqf b/addons/medical_statemachine/XEH_postInit.sqf index a7c7740a39..8a7ff28952 100644 --- a/addons/medical_statemachine/XEH_postInit.sqf +++ b/addons/medical_statemachine/XEH_postInit.sqf @@ -1,14 +1,18 @@ #include "script_component.hpp" -["ace_killed", { // global event - params ["_unit"]; +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; - // Prevent second ragdoll of uncon units when they're killed - if ( - IS_UNCONSCIOUS(_unit) && !isAwake _unit // uncon and not ragdolling - && {isPlayer _unit || {_unit getVariable [QGVAR(AIUnconsciousness), GVAR(AIUnconsciousness)]}} - ) then { - _unit enableSimulation false; - [{_this enableSimulation true}, _unit, 2] call CBA_fnc_waitAndExecute; - }; + ["ace_killed", { // global event + params ["_unit"]; + + // Prevent second ragdoll of uncon units when they're killed + if ( + IS_UNCONSCIOUS(_unit) && !isAwake _unit // uncon and not ragdolling + && {isPlayer _unit || {_unit getVariable [QGVAR(AIUnconsciousness), GVAR(AIUnconsciousness)]}} + ) then { + _unit enableSimulation false; + [{_this enableSimulation true}, _unit, 2] call CBA_fnc_waitAndExecute; + }; + }] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler; diff --git a/addons/medical_status/XEH_postInit.sqf b/addons/medical_status/XEH_postInit.sqf index 3f342987c9..36a64c6162 100644 --- a/addons/medical_status/XEH_postInit.sqf +++ b/addons/medical_status/XEH_postInit.sqf @@ -1,36 +1,41 @@ #include "script_component.hpp" -// Handle pain changes on injury -[QEGVAR(medical,injured), LINKFUNC(adjustPainLevel)] call CBA_fnc_addEventHandler; +["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; + // Handle pain changes on injury + [QEGVAR(medical,injured), LINKFUNC(adjustPainLevel)] call CBA_fnc_addEventHandler; -// Add inventory and open backpack actions to units -[QGVAR(addInventoryActions), LINKFUNC(addInventoryActions)] call CBA_fnc_addEventHandler; -// apply to all living and dead now -{ - [QGVAR(addInventoryActions), _x] call CBA_fnc_localEvent; -} forEach (allUnits + allDeadMen); -// apply to all future units -["CAManBase", "init", LINKFUNC(addInventoryActions), true, [], false] call CBA_fnc_addClassEventHandler; -// Respawn is called locally -["CAManBase", "respawn", { - params ["_unit"]; - if (!local _unit) exitWith {}; - [QGVAR(addInventoryActions), _unit] call CBA_fnc_globalEvent; -}, true] call CBA_fnc_addClassEventHandler; + // Add inventory and open backpack actions to units + [QGVAR(addInventoryActions), LINKFUNC(addInventoryActions)] call CBA_fnc_addEventHandler; + // Apply to all living and dead now + { + [QGVAR(addInventoryActions), _x] call CBA_fnc_localEvent; + } forEach (allUnits + allDeadMen); -// Handle comms status effects for spectator -// Separate from medical_feedback as these affect unit behavior rather than what the player sees -["featureCamera", { - params ["_unit", "_newCamera"]; + // Apply to all future units + ["CAManBase", "init", LINKFUNC(addInventoryActions), true, [], false] call CBA_fnc_addClassEventHandler; - if (_unit isNotEqualTo ACE_player) exitWith {}; + // Respawn is called locally + ["CAManBase", "respawn", { + params ["_unit"]; + if (!local _unit) exitWith {}; + [QGVAR(addInventoryActions), _unit] call CBA_fnc_globalEvent; + }, true] call CBA_fnc_addClassEventHandler; - if (_newCamera == "") then { // switched back to player view - private _status = IS_UNCONSCIOUS(_unit); - [_unit, _status] call FUNC(setStatusEffects); - } else { - [_unit, false, true] call FUNC(setStatusEffects); - }; -}] call CBA_fnc_addPlayerEventHandler; + // Handle comms status effects for spectator + // Separate from medical_feedback as these affect unit behavior rather than what the player sees + ["featureCamera", { + params ["_unit", "_newCamera"]; + + if (_unit isNotEqualTo ACE_player) exitWith {}; + + if (_newCamera == "") then { // switched back to player view + private _status = IS_UNCONSCIOUS(_unit); + [_unit, _status] call FUNC(setStatusEffects); + } else { + [_unit, false, true] call FUNC(setStatusEffects); + }; + }] call CBA_fnc_addPlayerEventHandler; +}] call CBA_fnc_addEventHandler; diff --git a/addons/medical_treatment/XEH_postInit.sqf b/addons/medical_treatment/XEH_postInit.sqf index 932ee43fb8..1746753dd8 100644 --- a/addons/medical_treatment/XEH_postInit.sqf +++ b/addons/medical_treatment/XEH_postInit.sqf @@ -1,41 +1,44 @@ #include "script_component.hpp" -[QEGVAR(medical_status,initialized), { - params ["_unit"]; - - // Clear all saved medical logs - { - _unit setVariable [_x, nil, true]; - } forEach (_unit getVariable [QEGVAR(medical,allLogs), []]); - - _unit setVariable [QEGVAR(medical,allLogs), [], true]; -}] call CBA_fnc_addEventHandler; - -// Handle body removal and litter on server -if (isServer) then { - [QGVAR(createLitterServer), LINKFUNC(createLitterServer)] call CBA_fnc_addEventHandler; - ["ace_placedInBodyBag", LINKFUNC(removeBody)] call CBA_fnc_addEventHandler; -}; - -// Treatment events -[QGVAR(bandageLocal), LINKFUNC(bandageLocal)] call CBA_fnc_addEventHandler; -[QGVAR(checkBloodPressureLocal), LINKFUNC(checkBloodPressureLocal)] call CBA_fnc_addEventHandler; -[QGVAR(checkPulseLocal), LINKFUNC(checkPulseLocal)] call CBA_fnc_addEventHandler; -[QGVAR(cprLocal), LINKFUNC(cprLocal)] call CBA_fnc_addEventHandler; -[QGVAR(fullHealLocal), LINKFUNC(fullHealLocal)] call CBA_fnc_addEventHandler; -[QGVAR(ivBagLocal), LINKFUNC(ivBagLocal)] call CBA_fnc_addEventHandler; -[QGVAR(medicationLocal), LINKFUNC(medicationLocal)] call CBA_fnc_addEventHandler; -[QGVAR(placeInBodyBagOrGrave), LINKFUNC(placeInBodyBagOrGrave)] call CBA_fnc_addEventHandler; -[QGVAR(splintLocal), LINKFUNC(splintLocal)] call CBA_fnc_addEventHandler; -[QGVAR(tourniquetLocal), LINKFUNC(tourniquetLocal)] call CBA_fnc_addEventHandler; - -// Logging events -[QGVAR(addToLog), LINKFUNC(addToLog)] call CBA_fnc_addEventHandler; -[QGVAR(addToTriageCard), LINKFUNC(addToTriageCard)] call CBA_fnc_addEventHandler; - -// replace medical items with their ACE equivalents ["CBA_settingsInitialized", { + if !(GETEGVAR(medical,enabled,false)) exitWith {}; + TRACE_1("CBA_settingsInitialized EH",GVAR(convertItems)); // 0: Enabled 1: RemoveOnly + + [QEGVAR(medical_status,initialized), { + params ["_unit"]; + + // Clear all saved medical logs + { + _unit setVariable [_x, nil, true]; + } forEach (_unit getVariable [QEGVAR(medical,allLogs), []]); + + _unit setVariable [QEGVAR(medical,allLogs), [], true]; + }] call CBA_fnc_addEventHandler; + + // Handle body removal and litter on server + if (isServer) then { + [QGVAR(createLitterServer), LINKFUNC(createLitterServer)] call CBA_fnc_addEventHandler; + ["ace_placedInBodyBag", LINKFUNC(removeBody)] call CBA_fnc_addEventHandler; + }; + + // Treatment events + [QGVAR(bandageLocal), LINKFUNC(bandageLocal)] call CBA_fnc_addEventHandler; + [QGVAR(checkBloodPressureLocal), LINKFUNC(checkBloodPressureLocal)] call CBA_fnc_addEventHandler; + [QGVAR(checkPulseLocal), LINKFUNC(checkPulseLocal)] call CBA_fnc_addEventHandler; + [QGVAR(cprLocal), LINKFUNC(cprLocal)] call CBA_fnc_addEventHandler; + [QGVAR(fullHealLocal), LINKFUNC(fullHealLocal)] call CBA_fnc_addEventHandler; + [QGVAR(ivBagLocal), LINKFUNC(ivBagLocal)] call CBA_fnc_addEventHandler; + [QGVAR(medicationLocal), LINKFUNC(medicationLocal)] call CBA_fnc_addEventHandler; + [QGVAR(placeInBodyBagOrGrave), LINKFUNC(placeInBodyBagOrGrave)] call CBA_fnc_addEventHandler; + [QGVAR(splintLocal), LINKFUNC(splintLocal)] call CBA_fnc_addEventHandler; + [QGVAR(tourniquetLocal), LINKFUNC(tourniquetLocal)] call CBA_fnc_addEventHandler; + + // Logging events + [QGVAR(addToLog), LINKFUNC(addToLog)] call CBA_fnc_addEventHandler; + [QGVAR(addToTriageCard), LINKFUNC(addToTriageCard)] call CBA_fnc_addEventHandler; + + // Replace medical items with their ACE equivalents { // turn [["stuff", 2], ...] into ["stuff", "stuff", ...] private _replacements = []; @@ -59,41 +62,43 @@ if (isServer) then { // register replacement [_toReplace, _replacements] call EFUNC(common,registerItemReplacement); } forEach (configProperties [configFile >> QEGVAR(medical,replacementItems), "isArray _x"]); + + if (["ace_trenches"] call EFUNC(common,isModLoaded)) then { + if (hasInterface) then { + private _checkHeadstoneAction = [ + QGVAR(checkHeadstone), + LLSTRING(checkHeadstoneName), + QPATHTOEF(medical_gui,ui\grave.paa), + { + [ + [_target getVariable QGVAR(headstoneData)], + true + ] call CBA_fnc_notify; + }, + {!isNil {_target getVariable QGVAR(headstoneData)}} + ] call EFUNC(interact_menu,createAction); + + [missionNameSpace getVariable [QGVAR(graveClassname), "ACE_Grave"], 0, [], _checkHeadstoneAction] call EFUNC(interact_menu,addActionToClass); + }; + + if (isServer) then { + ["ace_placedInBodyBag", { + params ["_target", "_restingPlace"]; + + TRACE_2("ace_placedInBodyBag eh",_target,_restingPlace); + + if (isNull _restingPlace) exitWith {}; + + private _targetName = if (_target isKindOf "ACE_bodyBagObject") then { + _target getVariable [QGVAR(headstoneData), ""] + } else { + [_target, false, true] call EFUNC(common,getName) + }; + + if (_targetName == "") exitWith {}; + + _restingPlace setVariable [QGVAR(headstoneData), _targetName, true]; + }] call CBA_fnc_addEventHandler; + }; + }; }] call CBA_fnc_addEventHandler; - -if (["ace_trenches"] call EFUNC(common,isModLoaded)) then { - if (hasInterface) then { - private _checkHeadstoneAction = [ - QGVAR(checkHeadstone), - LLSTRING(checkHeadstoneName), - QPATHTOEF(medical_gui,ui\grave.paa), - { - [ - [_target getVariable QGVAR(headstoneData)], - true - ] call CBA_fnc_notify; - }, - {!isNil {_target getVariable QGVAR(headstoneData)}} - ] call EFUNC(interact_menu,createAction); - - [missionNameSpace getVariable [QGVAR(graveClassname), "ACE_Grave"], 0, [], _checkHeadstoneAction] call EFUNC(interact_menu,addActionToClass); - }; - - if (isServer) then { - ["ace_placedInBodyBag", { - params ["_target", "_restingPlace"]; - TRACE_2("ace_placedInBodyBag eh",_target,_restingPlace); - if (isNull _restingPlace) exitWith {}; - - private _targetName = ""; - if (_target isKindOf "ACE_bodyBagObject") then { - _targetName = _target getVariable [QGVAR(headstoneData), ""]; - } else { - _targetName = [_target, false, true] call EFUNC(common,getName); - }; - - if (_targetName == "") exitWith {}; - _restingPlace setVariable [QGVAR(headstoneData), _targetName, true]; - }] call CBA_fnc_addEventHandler; - }; -}; diff --git a/addons/medical_treatment/functions/fnc_canUnloadUnit.sqf b/addons/medical_treatment/functions/fnc_canUnloadUnit.sqf index f1a15f04f9..7a00aa8ead 100644 --- a/addons/medical_treatment/functions/fnc_canUnloadUnit.sqf +++ b/addons/medical_treatment/functions/fnc_canUnloadUnit.sqf @@ -16,6 +16,8 @@ * Public: No */ +if !(GETEGVAR(medical,enabled,false)) exitWith {false}; + params ["_unloader", "_target"]; !isNull objectParent _target && diff --git a/addons/zeus/functions/fnc_moduleUnconscious.sqf b/addons/zeus/functions/fnc_moduleUnconscious.sqf index 7eede3cdec..bd3def1c68 100644 --- a/addons/zeus/functions/fnc_moduleUnconscious.sqf +++ b/addons/zeus/functions/fnc_moduleUnconscious.sqf @@ -21,7 +21,7 @@ params ["_logic"]; if !(local _logic) exitWith {}; -if (isNil QEFUNC(medical,setUnconscious)) then { +if !(GETEGVAR(medical,enabled,false)) then { [LSTRING(RequiresAddon)] call FUNC(showMessage); } else { private _mouseOver = GETMVAR(bis_fnc_curatorObjectPlaced_mouseOver,[""]);