From 6ca29abfdcdd9b3fa21d116249bf629501853fc8 Mon Sep 17 00:00:00 2001 From: Cplhardcore <135324281+Cplhardcore@users.noreply.github.com> Date: Sat, 16 Nov 2024 15:58:36 -0800 Subject: [PATCH] overwrites and small changes --- addons/pharma/CfgFunctions.hpp | 3 + .../functions/fnc_onMedicationUsage.sqf | 82 +++++++++++++++++++ addons/pharma/functions/fnc_overDose.sqf | 34 ++++---- 3 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 addons/pharma/functions/fnc_onMedicationUsage.sqf diff --git a/addons/pharma/CfgFunctions.hpp b/addons/pharma/CfgFunctions.hpp index d55116ed7..0e95d25ee 100644 --- a/addons/pharma/CfgFunctions.hpp +++ b/addons/pharma/CfgFunctions.hpp @@ -20,6 +20,9 @@ class CfgFunctions { class overDose { file = QPATHTOF(functions\fnc_overDose.sqf); }; + class onMedicationUsage { + file = QPATHTOF(functions\fnc_onMedicationUsage.sqf); + }; }; }; }; diff --git a/addons/pharma/functions/fnc_onMedicationUsage.sqf b/addons/pharma/functions/fnc_onMedicationUsage.sqf new file mode 100644 index 000000000..98be2bee6 --- /dev/null +++ b/addons/pharma/functions/fnc_onMedicationUsage.sqf @@ -0,0 +1,82 @@ +#include "..\script_component.hpp" +/* + * Author: Glowbal, Cplhardcore + * Handles the medication given to a patient. + * + * Arguments: + * 0: Patient + * 1: Medication Treatment classname + * 2: Incompatible medication > + * + * Return Value: + * None + * + * Example: + * [player, "morphine", [["x", 1]]] call ace_medical_treatment_fnc_onMedicationUsage + * + * Public: No + */ + +params ["_target", "_className", "_incompatibleMedication"]; +TRACE_3("onMedicationUsage",_target,_className,_incompatibleMedication); + +if (QGVAR(AMS_Enabled)) then { + private _medicationParts = (_className splitString "_"); + + if (count _medicationParts > 3) then { + _medicationName = _medicationParts select 1; { + private _defaultConfig = configFile >> QUOTE(ADDON) >> "Medication"; + private _medicationConfig = _defaultConfig >> _medicationName; + private _maxDose = GET_NUMBER(_medicationConfig >> "maxDose",getNumber (_defaultConfig >> "maxDose")); + + if (_maxDose > 0) then { + private _maxDoseDeviation = GET_NUMBER(_medicationConfig >> "maxDoseDeviation",getNumber (_defaultConfig >> "maxDoseDeviation")); + private _currentDose = [_target, _medicationName] call EFUNC(medical_status,getMedicationCount) select 0; + // Because both {floor random 0} and {floor random 1} return 0 + if (_maxDoseDeviation > 0) then { + _maxDoseDeviation = _maxDoseDeviation + 1; + }; + + private _limit = _maxDose + (floor random _maxDoseDeviation); + if (_currentDose > _limit) then { + TRACE_1("exceeded max dose",_currentDose); + [_target, _medicationName, _currentDose, _limit, _incompatibleMed] call FUNC(overDose); + }; + { + _x params ["_xMed", "_xLimit"]; + private _inSystem = ([_target, _xMed] call EFUNC(medical_status,getMedicationCount)) select 0; + if (_inSystem > _xLimit) then { + [_target, _medicationName, _inSystem, _xLimit, _xMed] call FUNC(overDose); + }; + } forEach _incompatibleMedication; + }; + }; + }; +} else { + private _defaultConfig = configFile >> QUOTE(ADDON) >> "Medication"; + private _medicationConfig = _defaultConfig >> _classname; + private _maxDose = GET_NUMBER(_medicationConfig >> "maxDose",getNumber (_defaultConfig >> "maxDose")); + + if (_maxDose > 0) then { + private _maxDoseDeviation = GET_NUMBER(_medicationConfig >> "maxDoseDeviation",getNumber (_defaultConfig >> "maxDoseDeviation")); + private _currentDose = [_target, _className] call EFUNC(medical_status,getMedicationCount) select 0; + // Because both {floor random 0} and {floor random 1} return 0 + if (_maxDoseDeviation > 0) then { + _maxDoseDeviation = _maxDoseDeviation + 1; + }; + + private _limit = _maxDose + (floor random _maxDoseDeviation); + if (_currentDose > _limit) then { + TRACE_1("exceeded max dose",_currentDose); + [_target, _classname, _currentDose, _limit, _classname] call FUNC(overDose); + }; + }; + +// Check incompatible medication (format [med,limit]) + { + _x params ["_xMed", "_xLimit"]; + private _inSystem = ([_target, _xMed] call EFUNC(medical_status,getMedicationCount)) select 0; + if (_inSystem > _xLimit) then { + [_target, _classname, _inSystem, _xLimit, _xMed] call FUNC(overDose); + }; + } forEach _incompatibleMedication;} diff --git a/addons/pharma/functions/fnc_overDose.sqf b/addons/pharma/functions/fnc_overDose.sqf index 209bf07e7..cf8f8bde5 100644 --- a/addons/pharma/functions/fnc_overDose.sqf +++ b/addons/pharma/functions/fnc_overDose.sqf @@ -16,34 +16,34 @@ * Public: No */ -params ["_unit", "_classname"]; +params ["_unit", "_className", "_dose", "_limit", "_incompatibleMedication"]; if (QGVAR(AMS_Enabled)) then { - private _medicationParts = (_className splitString "_"); - - if (count _medicationParts > 3) then { - _medicationName = _medicationParts select 1; - [format ["kat_pharma_%1OverdoseLocal", toLower _medicationName], [_patient], _patient] call CBA_fnc_targetEvent; + [format ["kat_pharma_%1OverdoseLocal", toLower _className], [_patient], _patient] call CBA_fnc_targetEvent; }; - } else { private _defaultConfig = configFile >> QUOTE(ACE_ADDON(Medical_Treatment)) >> "Medication"; private _medicationConfig = (configFile >> "ace_medical_treatment" >> _classname); private _onOverDose = getText (_medicationConfig >> "onOverDose"); - if (isClass (_medicationConfig)) then { - _medicationConfig = (_medicationConfig >> _classname); - if (isText (_medicationConfig >> "onOverDose")) then { - _onOverDose = getText (_medicationConfig >> "onOverDose"); + if (isClass _medicationConfig) then { + _medicationConfig = _medicationConfig >> _classname; + if (isText (_medicationConfig >> "onOverDose")) then { + _onOverDose = getText (_medicationConfig >> "onOverDose"); }; }; TRACE_2("overdose",_classname,_onOverDose); + + [QEGVAR(medical,overdose), [_unit, _classname, _dose, _limit, _incompatibleMed]] call CBA_fnc_localEvent; + if (_onOverDose == "") exitWith { - TRACE_1("CriticalVitals Event",_unit); - [QEGVAR(medical,CriticalVitals), _unit] call CBA_fnc_localEvent; + TRACE_1("CriticalVitals Event",_unit); + [QEGVAR(medical,CriticalVitals), _unit] call CBA_fnc_localEvent; }; - if (!isNil "_onOverDose" && {isText _onOverDose}) then { - _onOverDose = compile _onOverDose; + + _onOverDose = if (missionNamespace isNil _onOverDose) then { + compile _onOverDose } else { - _onOverDose = missionNamespace getVariable _onOverDose; + missionNamespace getVariable _onOverDose }; - [_target, _className] call _onOverDose;}; \ No newline at end of file + + [_unit, _classname, _dose, _limit, _incompatibleMed] call _onOverDose}; \ No newline at end of file