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 - Add 'Open (Backpack)' action to dead units #9239

Merged
merged 12 commits into from
Sep 4, 2023
1 change: 1 addition & 0 deletions addons/medical_status/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(addInventoryActions);
PREP(addMedicationAdjustment);
PREP(adjustPainLevel);
PREP(getBloodLoss);
Expand Down
17 changes: 17 additions & 0 deletions addons/medical_status/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
// 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;


// Handle comms status effects for spectator
// Separate from medical_feedback as these affect unit behavior rather than what the player sees
["featureCamera", {
Expand Down
16 changes: 0 additions & 16 deletions addons/medical_status/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,4 @@ PREP_RECOMPILE_END;

addMissionEventHandler ["EntityKilled", {_this call FUNC(handleKilledMission)}];

if (hasInterface) then {
//Add Inventory action to uncon units
["CAManBase", "init", {
params ["_unit"];

private _id = _unit addAction ["", {
params ["_target", "_caller", "_actionId", "_arguments"];

_caller action ["Gear", _target];
}, nil, 5.1, true, true, "gear", "_target getVariable ['ACE_isUnconscious',false] && {alive _target}", 3.5];

_unit setUserActionText [_id, localize "STR_ACTION_GEAR", "<img image='\A3\ui_f\data\igui\cfg\actions\gear_ca.paa' size='2.5' shadow=2 />"];

}, nil, nil, true] call CBA_fnc_addClassEventHandler;
};

ADDON = true;
50 changes: 50 additions & 0 deletions addons/medical_status/functions/fnc_addInventoryActions.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "script_component.hpp"
/*
* Author: LinkIsGrim, johnb43
* Adds inventory and open backpack actions to uncon units.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [cursorTarget] call ace_medical_status_fnc_addInventoryActions
*
* Public: No
*/

if (!hasInterface) exitWith {};

params ["_unit"];

// Gear Action - For Unconscious Units
private _id = _unit addAction ["", {
params ["_target", "_caller"];

_caller action ["Gear", _target];
}, nil, 5.1, true, true, "gear", toString {
(_target isNotEqualTo ACE_player) &&
{(lifeState _target) isEqualTo "INCAPACITATED"}
}, 2];

_unit setUserActionText [_id, localize "STR_ACTION_GEAR", "<img image='\A3\ui_f\data\igui\cfg\actions\gear_ca.paa' size='2.5' shadow=2 />"];

// Open Bag Action - For Dead Units
_unit addAction ["OpenBag", {
params ["_target", "_caller"];

_caller action ["OpenBag", _target];
}, nil, 5.2, true, true, "", toString {
private _backpackContainer = backpackContainer _target;
private _backpackConfig = configOf _backpackContainer;

(_target isNotEqualTo ACE_player) &&
{!((lifeState _target) in ["HEALTHY", "INJURED", "INCAPACITATED"])} &&
{!isNull _backpackContainer} &&
{!lockedInventory _backpackContainer} &&
{maxLoad _backpackContainer > 0} &&
{getNumber (_backpackConfig >> "disableInventory") != 1} &&
{_target setUserActionText [_actionId, format [localize "STR_ACTION_OPEN_BAG", getText (_backpackConfig >> "displayName")]]; true}
}, 2];