2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-07-15 10:23:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Handles the medication given to a patient.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: The patient <OBJECT>
|
|
|
|
* 1: Medication Treatment classname <STRING>
|
2024-02-13 10:45:04 +00:00
|
|
|
* 2: Max dose (0 to ignore) <NUMBER>
|
|
|
|
* 3: Max dose deviation <NUMBER>
|
2019-04-27 19:12:11 +00:00
|
|
|
* 3: Incompatable medication <ARRAY<STRING>>
|
2016-07-15 10:23:47 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
2024-02-13 10:45:04 +00:00
|
|
|
* [player, "morphine", 4, 2, [["x", 1]]] call ace_medical_treatment_fnc_onMedicationUsage
|
2017-06-08 13:31:51 +00:00
|
|
|
*
|
2016-07-15 10:23:47 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2024-02-13 10:45:04 +00:00
|
|
|
params ["_target", "_className", "_maxDose", "_maxDoseDeviation", "_incompatibleMedication"];
|
|
|
|
TRACE_5("onMedicationUsage",_target,_className,_maxDose,_maxDoseDeviation,_incompatibleMedication);
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2019-04-27 19:12:11 +00:00
|
|
|
private _overdosedMedications = [];
|
|
|
|
|
|
|
|
// Check for overdose from current medication
|
2024-02-13 10:45:04 +00:00
|
|
|
if (_maxDose > 0) then {
|
2019-09-28 21:11:32 +00:00
|
|
|
private _currentDose = [_target, _className] call EFUNC(medical_status,getMedicationCount);
|
2024-02-13 10:45:04 +00:00
|
|
|
// Because both {floor random 0} and {floor random 1} return 0
|
|
|
|
if (_maxDoseDeviation > 0) then {
|
|
|
|
_maxDoseDeviation = _maxDoseDeviation + 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_currentDose > _maxDose + (floor random _maxDoseDeviation)) then {
|
2019-09-28 21:11:32 +00:00
|
|
|
TRACE_1("exceeded max dose",_currentDose);
|
|
|
|
_overdosedMedications pushBackUnique _className;
|
|
|
|
};
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
2019-04-27 19:12:11 +00:00
|
|
|
// Check incompatible medication (format [med,limit])
|
2016-07-15 10:23:47 +00:00
|
|
|
{
|
2019-04-27 19:12:11 +00:00
|
|
|
_x params ["_xMed", "_xLimit"];
|
2019-09-28 21:11:32 +00:00
|
|
|
private _inSystem = [_target, _xMed] call EFUNC(medical_status,getMedicationCount);
|
2019-04-27 19:12:11 +00:00
|
|
|
if (_inSystem> _xLimit) then {
|
|
|
|
_overdosedMedications pushBackUnique _xMed;
|
|
|
|
};
|
2019-06-03 15:31:46 +00:00
|
|
|
} forEach _incompatibleMedication;
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_overdosedMedications isNotEqualTo []) then {
|
2016-07-15 10:23:47 +00:00
|
|
|
private _medicationConfig = (configFile >> "ace_medical_treatment" >> "Medication");
|
|
|
|
private _onOverDose = getText (_medicationConfig >> "onOverDose");
|
|
|
|
if (isClass (_medicationConfig >> _className)) then {
|
|
|
|
_medicationConfig = (_medicationConfig >> _className);
|
2019-04-27 19:12:11 +00:00
|
|
|
if (isText (_medicationConfig >> "onOverDose")) then { _onOverDose = getText (_medicationConfig >> "onOverDose"); };
|
|
|
|
};
|
|
|
|
TRACE_2("overdose",_overdosedMedications,_onOverDose);
|
|
|
|
if (_onOverDose == "") exitWith {
|
|
|
|
TRACE_1("CriticalVitals Event",_target); // make unconscious
|
|
|
|
[QEGVAR(medical,CriticalVitals), _target] call CBA_fnc_localEvent;
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
if (isNil _onOverDose) then {
|
|
|
|
_onOverDose = compile _onOverDose;
|
|
|
|
} else {
|
|
|
|
_onOverDose = missionNamespace getVariable _onOverDose;
|
|
|
|
};
|
2019-04-27 19:12:11 +00:00
|
|
|
[_target, _className, _overdosedMedications] call _onOverDose;
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|