Medical Engine - Prevent automatic unloading of dead or unconscious units (#7959)

* Lock seats of unconscious or dead units

* disable pullOutBody if medical is loaded

* fix undefined var and switch to objectParent

---------

Co-authored-by: Salluci <salluci.lovi@gmail.com>
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
This commit is contained in:
BaerMitUmlaut 2023-07-22 08:41:20 +02:00 committed by GitHub
parent 4f4389dd59
commit 52ed0fc6be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 103 additions and 3 deletions

View File

@ -18,6 +18,9 @@
params ["_body", "_unit"]; params ["_body", "_unit"];
// Defer to ACE Medical's unload patient if present
if (["ace_medical"] call EFUNC(common,isModLoaded)) exitWith {false};
private _vehicle = objectParent _body; private _vehicle = objectParent _body;
if ( if (

View File

@ -4,7 +4,9 @@ PREP(disableThirdParty);
PREP(getHitpointArmor); PREP(getHitpointArmor);
PREP(getItemArmor); PREP(getItemArmor);
PREP(handleDamage); PREP(handleDamage);
PREP(lockUnconsciousSeat);
PREP(setStructuralDamage); PREP(setStructuralDamage);
PREP(setUnconsciousAnim); PREP(setUnconsciousAnim);
PREP(unlockUnconsciousSeat);
PREP(updateBodyPartVisuals); PREP(updateBodyPartVisuals);
PREP(updateDamageEffects); PREP(updateDamageEffects);

View File

@ -42,12 +42,23 @@
// this handles moving units into vehicles via load functions or zeus // this handles moving units into vehicles via load functions or zeus
// needed, because the vanilla INCAPACITATED state does not handle vehicles // needed, because the vanilla INCAPACITATED state does not handle vehicles
["CAManBase", "GetInMan", { ["CAManBase", "GetInMan", {
params ["_unit"]; params ["_unit", "", "_vehicle"];
if (!local _unit) exitWith {};
if (lifeState _unit == "INCAPACITATED") then { if (local _unit && {lifeState _unit == "INCAPACITATED"}) then {
[_unit, true] call FUNC(setUnconsciousAnim); [_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; }] call CBA_fnc_addClassEventHandler;
// Guarantee aircraft crashes are more lethal // Guarantee aircraft crashes are more lethal
@ -71,3 +82,15 @@
[_unit, false] call FUNC(setUnconsciousAnim); [_unit, false] call FUNC(setUnconsciousAnim);
}; };
}] call CBA_fnc_addClassEventHandler; }] call CBA_fnc_addClassEventHandler;
["ace_unconscious", {
params ["_unit", "_unconscious"];
if (vehicle _unit != _unit && {local vehicle _unit}) then {
if (_unconscious) then {
[_unit] call FUNC(lockUnconsciousSeat);
} else {
[_unit] call FUNC(unlockUnconsciousSeat);
};
};
}] call CBA_fnc_addEventHandler;

View File

@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
* Locks the seat of an unconscious or dead unit to prevent automatic unloading.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
params ["_unit"];
private _vehicle = objectParent _unit;
if (alive _unit && {lifeState _unit != "INCAPACITATED"}) exitWith {};
switch (true) do {
case (_unit isEqualTo (driver _vehicle)): {
_vehicle lockDriver true;
_unit setVariable [QGVAR(lockedSeat), [_vehicle, "driver"], true];
};
case (_vehicle getCargoIndex _unit != -1): {
private _cargoIndex = _vehicle getCargoIndex _unit;
_vehicle lockCargo [_cargoIndex, true];
_unit setVariable [QGVAR(lockedSeat), [_vehicle, "cargo", _cargoIndex], true];
};
case ((_vehicle unitTurret _unit) isNotEqualTo []): {
private _turretPath = _vehicle unitTurret _unit;
_vehicle lockTurret [_turretPath, true];
_unit setVariable [QGVAR(lockedSeat), [_vehicle, "turret", _turretPath], true];
};
};

View File

@ -0,0 +1,35 @@
#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
* Unlocks the seat of an unconscious or dead unit after getting moved out or waking up.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
params ["_unit"];
private _seat = _unit getVariable [QGVAR(lockedSeat), []];
_seat params ["_vehicle", "_type", "_position"];
if (_seat isEqualTo []) exitWith {};
switch (_type) do {
case "driver": {
_vehicle lockDriver false;
};
case "cargo": {
_vehicle lockCargo [_position, false];
};
case "turret": {
_vehicle lockTurret [_position, false];
};
};
_unit setVariable [QGVAR(lockedSeat), nil, true];