Skip to content

Commit

Permalink
overwrites and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cplhardcore committed Nov 16, 2024
1 parent 780fd5e commit 6ca29ab
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 17 deletions.
3 changes: 3 additions & 0 deletions addons/pharma/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class CfgFunctions {
class overDose {
file = QPATHTOF(functions\fnc_overDose.sqf);
};
class onMedicationUsage {
file = QPATHTOF(functions\fnc_onMedicationUsage.sqf);
};
};
};
};
82 changes: 82 additions & 0 deletions addons/pharma/functions/fnc_onMedicationUsage.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "..\script_component.hpp"
/*
* Author: Glowbal, Cplhardcore
* Handles the medication given to a patient.
*
* Arguments:
* 0: Patient <OBJECT>
* 1: Medication Treatment classname <STRING>
* 2: Incompatible medication <ARRAY of <STRING, NUMBER>>
*
* 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;}
34 changes: 17 additions & 17 deletions addons/pharma/functions/fnc_overDose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 23 in addons/pharma/functions/fnc_overDose.sqf

View workflow job for this annotation

GitHub Actions / build

unparseable syntax

unparseable syntax
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;};

[_unit, _classname, _dose, _limit, _incompatibleMed] call _onOverDose};

0 comments on commit 6ca29ab

Please sign in to comment.